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, BlueprintReadWrite)
32 UInstancedStaticMeshComponent* InstancedStaticMeshComponent;
34 UPROPERTY(EditAnywhere, BlueprintReadWrite)
35 TSubclassOf<AActor> ActorClass;
37 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
38 TWeakObjectPtr<UStaticMesh> Mesh;
40 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
41 TArray<UMaterialInterface*> Materials;
43 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
44 int32 InstanceEntryIndex = 0;
46 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
47 int32 CustomDepthStencilValue;
49 UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
50 bool AllowWorldPositionOffsetDisable = false;
52 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
55 bool UsingProxy = false;
87 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
95 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
96 void RemoveInstance(int32 ComponentIndex, int32 InstanceNumber);
104 void UpdateInstanceTransform(int32 ComponentIndex, int32 InstanceNumber,
const FTransform& NewTransform);
109 UFUNCTION(BlueprintPure, Category =
"Instanced Renderer")
110 bool IsRendering()
const
119 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
120 int32 GetTotalInstanceCount()
const
122 return TotalInstanceCount;
129 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
130 int32 GetUniqueInstancesCount()
const
132 return InstanceEntries.Num();
139 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
142 return InstanceEntries;
148 UFUNCTION(BlueprintCallable, Category =
"Instanced Renderer")
149 void SetInstancedRendering(
bool ShouldRender);
156 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
157 void SetComponentIndexVisibility(int32 Index,
bool Visible);
163 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
164 void SetRenderCustomDepth(
bool Enabled);
170 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
171 void SetWorldPositionOffsetDistance(int32 NewWPODistance);
177 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
178 void SetShadowCacheBehaviour(EShadowCacheInvalidationBehavior ShadowCacheInvalidationBehaviour);
184 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
185 void SetRenderWorldPositionOffet(
bool RenderWPO);
190 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
191 void LogInfo() const;
197 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
198 void DebugMaterialImpact(
bool SetUnrealDefaultMaterial);
200 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
201 void ToggleProxyMesh();
203 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
204 void SpawnAllInstancesBackActors();
209 UFUNCTION(BlueprintCallable, Category = "Instanced Renderer")
210 bool SpawnInstanceBackToActor(UInstancedStaticMeshComponent* ISM, int32 Index);
223 UPROPERTY(VisibleAnywhere, AdvancedDisplay, BlueprintReadWrite)
226 UPROPERTY(BlueprintReadWrite)
227 TArray<UInstancedStaticMeshComponent*> InstancesStaticMeshComponents;
229 UPROPERTY(VisibleAnywhere, BlueprintReadOnly)
230 int32 TotalInstanceCount = 0;
234 TWeakObjectPtr<UStaticMesh> ProxyMesh;
238 virtual
void BeginPlay() override;
240 virtual
void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
252 int32 FindOrAddUniqueMesh(UStaticMeshComponent* StaticMeshComponent,
AInstancedActor* InstancedActor);
257 int32 WorldPositionOffsetDistance = 30000;
261 bool Rendering = true;
263 bool RenderingWPO = true;