8#include "CoreMinimal.h"
9#include "GameFramework/Actor.h"
10#include "Engine/EngineTypes.h"
11#include "Engine/StaticMesh.h"
12#include "Materials/MaterialInterface.h"
13#include "Components/InstancedStaticMeshComponent.h"
14#include "Components/StaticMeshComponent.h"
24#include "InstancedRenderer.generated.h"
31 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
32 UInstancedStaticMeshComponent* InstancedStaticMeshComponent;
34 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
37 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
38 TWeakObjectPtr<UStaticMesh> Mesh;
40 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
41 TArray<UMaterialInterface*> Materials;
43 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
46 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
47 int32 InstanceEntryIndex = 0;
49 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
50 bool AllowWorldPositionOffsetDisable = false;
83 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
84 void RemoveInstance(int32 ComponentIndex, int32 InstanceNumber);
91 void AddOrRemoveActorFromAutomaticTransformUpdates(
bool Add,
AInstancedActor* InstancedActor);
99 void UpdateInstanceTransform(int32 ComponentIndex, int32 InstanceNumber,
const FTransform& NewTransform);
104 UFUNCTION(BlueprintPure, Category =
"Instanced Renderer")
105 bool IsRendering()
const
114 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
115 int32 GetTotalInstanceCount()
const
117 return TotalInstanceCount;
124 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
125 int32 GetUniqueInstancesCount()
const
127 return InstanceEntries.Num();
134 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
137 return InstanceEntries;
143 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
144 void SetInstancedRendering(
bool ShouldRender);
151 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
152 void SetComponentIndexVisibility(int32 Index,
bool Visible);
158 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
159 void SetRenderCustomDepth(
bool Enabled);
165 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
166 void SetWorldPositionOffsetDistance(int32 NewWPODistance);
172 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
173 void SetShadowCacheBehaviour(EShadowCacheInvalidationBehavior ShadowCacheInvalidationBehaviour);
179 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
180 void SetRenderWorldPositionOffet(
bool RenderWPO);
185 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
186 void LogInfo() const;
192 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
193 void DebugMaterialImpact(
bool SetUnrealDefaultMaterial);
199 void BeginPlay() override;
201 void Tick(
float DeltaTime) override;
203 void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
211 bool AreTransformsEqual(const FTransform& TransformA, const FTransform& TransformB) const;
216 void UpdateInstancedActors();
222 int32 FindOrAddUniqueMesh(UStaticMeshComponent* StaticMeshComponent,
AInstancedActor* InstancedActor);
228 UPROPERTY(VisibleAnywhere)
234 int32 WorldPositionOffsetDistance = 30000;
240 int32 TotalInstanceCount;
242 bool Rendering = true;
244 bool RenderingWPO = true;