UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
InstancedFoliageActor.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3
4#pragma once
5
6#include "CoreMinimal.h"
9#include "Engine/World.h"
10#include "GameFramework/Actor.h"
12#include "FoliageInstanceBase.h"
13#include "InstancedFoliage.h"
16
17#include "InstancedFoliageActor.generated.h"
18
19#if WITH_EDITOR
22#endif
23
24// Function for filtering out hit components during FoliageTrace
25typedef TFunction<bool(const UPrimitiveComponent*)> FFoliageTraceFilterFunc;
26
27UCLASS(notplaceable, hidecategories = (Object, Rendering, Mobility), MinimalAPI, NotBlueprintable)
29{
31
32public:
33#if WITH_EDITORONLY_DATA
34 // Cross level references cache for instances base
35 FFoliageInstanceBaseCache InstanceBaseCache;
36
38#endif// WITH_EDITORONLY_DATA
39
40private:
41 friend struct FFoliageInstanceBaseCache;
42
44
45public:
46 FOLIAGE_API bool ForEachFoliageInfo(TFunctionRef<bool(UFoliageType* FoliageType, FFoliageInfo& FoliageInfo)> InOperation);
48 FOLIAGE_API TUniqueObj<FFoliageInfo>& AddFoliageInfo(UFoliageType* FoliageType);
50 FOLIAGE_API bool RemoveFoliageInfoAndCopyValue(UFoliageType* FoliageType, TUniqueObj<FFoliageInfo>& OutFoliageInfo);
51
52 //~ Begin UObject Interface.
53 virtual void Serialize(FArchive& Ar) override;
54 virtual void PostLoad() override;
55#if WITH_EDITORONLY_DATA
57#endif
58
59 static void AddReferencedObjects(UObject* InThis, FReferenceCollector& Collector);
60 //~ End UObject Interface.
61
62 //~ Begin AActor Interface.
63 // we don't want to have our components automatically destroyed by the Blueprint code
64#if WITH_EDITOR
65 virtual void RerunConstructionScripts() override {}
66#endif
67 virtual bool IsLevelBoundsRelevant() const override { return false; }
68
69public:
70#if WITH_EDITOR
71 bool CanDeleteSelectedActor(FText& OutReason) const override { return true; }
72 bool CanEditFoliageInstance(const FFoliageInstanceId& InstanceId) const;
73 bool CanMoveFoliageInstance(const FFoliageInstanceId& InstanceId, const ETypedElementWorldType WorldType) const;
74 bool GetFoliageInstanceTransform(const FFoliageInstanceId& InstanceId, FTransform& OutInstanceTransform, bool bWorldSpace) const;
75 bool SetFoliageInstanceTransform(const FFoliageInstanceId& InstanceId, const FTransform& InstanceTransform, bool bWorldSpace, bool bTeleport);
79 void NotifyFoliageInstanceSelectionChanged(const FFoliageInstanceId& InstanceId, const bool bIsSelected);
82
84#endif
85
86protected:
87#if WITH_EDITOR
90#endif
91
92 //~ ISMInstanceManagerProvider interface
93 virtual ISMInstanceManager* GetSMInstanceManager(const FSMInstanceId& InstanceId) override;
94
95 // Default InternalTakeRadialDamage behavior finds and scales damage for the closest component which isn't appropriate for foliage.
96 virtual float InternalTakeRadialDamage(float Damage, struct FRadialDamageEvent const& RadialDamageEvent, class AController* EventInstigator, AActor* DamageCauser) override;
97
98public:
99#if WITH_EDITOR
102
103 virtual void PostInitProperties() override;
104 virtual void BeginDestroy() override;
105 virtual void Destroyed() override;
106 virtual bool IsListedInSceneOutliner() const override;
107
110
111 virtual uint32 GetDefaultGridSize(UWorld* InWorld) const override;
113
114 // Delegate type for selection change events
115 DECLARE_MULTICAST_DELEGATE_TwoParams(FOnSelectionChanged, bool, const TArray<AActor*>&);
116 FOLIAGE_API static FOnSelectionChanged SelectionChanged;
117
120#endif
121 //~ End AActor Interface.
122
123
124 // Performs a reverse lookup from a source object to a local foliage type (i.e. the foliage type owned exclusively by this IFA)
125 FOLIAGE_API UFoliageType* GetLocalFoliageTypeForSource(const UObject* InSource, FFoliageInfo** OutMeshInfo = nullptr);
126
127 // Performs a reverse lookup from a source object to all the foliage types that are currently using that object (includes assets and blueprint classes)
128 FOLIAGE_API void GetAllFoliageTypesForSource(const UObject* InSource, TArray<const UFoliageType*>& OutFoliageTypes);
129
131
132 // Finds the number of instances overlapping with the sphere.
133 FOLIAGE_API int32 GetOverlappingSphereCount(const UFoliageType* FoliageType, const FSphere& Sphere) const;
134 // Finds the number of instances overlapping with the box.
135 FOLIAGE_API int32 GetOverlappingBoxCount(const UFoliageType* FoliageType, const FBox& Box) const;
136 // Finds all instances in the provided box and get their transforms
137 FOLIAGE_API void GetOverlappingBoxTransforms(const UFoliageType* FoliageType, const FBox& Box, TArray<FTransform>& OutTransforms) const;
138 // Perf Warnin: potentially slow! Dev-only use recommended.
139 // Returns list of meshes and counts for all nearby instances. OutCounts accumulates between runs.
140 FOLIAGE_API void GetOverlappingMeshCounts(const FSphere& Sphere, TMap<UStaticMesh*, int32>& OutCounts) const;
141
142 // Finds a mesh entry
144
145 // Finds a mesh entry
146 FOLIAGE_API const FFoliageInfo* FindInfo(const UFoliageType* InType) const;
147
155 static FOLIAGE_API AInstancedFoliageActor* GetInstancedFoliageActorForCurrentLevel(const UWorld* InWorld, bool bCreateIfNone = false);
156
157
164 static FOLIAGE_API AInstancedFoliageActor* GetInstancedFoliageActorForLevel(ULevel* Level, bool bCreateIfNone = false);
165
166#if WITH_EDITOR
175
177
180
182 static FOLIAGE_API bool CheckCollisionWithWorld(const UWorld* InWorld, const UFoliageType* Settings, const FFoliageInstance& Inst, const FVector& HitNormal, const FVector& HitLocation, UPrimitiveComponent* HitComponent);
183
184 virtual void PreEditUndo() override;
185 virtual void PostEditUndo() override;
186 virtual void PostDuplicate(bool bDuplicateForPIE) override;
187 virtual bool ShouldExport() override;
188 virtual bool ShouldImport(FStringView ActorPropString, bool IsMovingLevel) override;
189
190 // Called in response to BSP rebuilds to migrate foliage from obsolete to new components.
191 FOLIAGE_API void MapRebuild();
192
193 // Moves instances based on the specified component to the current streaming level
196
197 // Change all instances based on one component to a new component (possible in another level).
198 // The instances keep the same world locations
199 FOLIAGE_API void MoveInstancesToNewComponent(UPrimitiveComponent* InOldComponent, UPrimitiveComponent* InNewComponent);
200 FOLIAGE_API void MoveInstancesToNewComponent(UPrimitiveComponent* InOldComponent, const FBox& InBoxWithInstancesToMove, UPrimitiveComponent* InNewComponent);
201 static FOLIAGE_API void MoveInstancesToNewComponent(UWorld* InWorld, UPrimitiveComponent* InOldComponent, const FBox& InBoxWithInstancesToMove, UPrimitiveComponent* InNewComponent);
202 static FOLIAGE_API void MoveInstancesToNewComponent(UWorld* InWorld, UPrimitiveComponent* InOldComponent, UPrimitiveComponent* InNewComponent);
203
204 // Move selected instances to a foliage actor in target level
206
207 // Move all instances to a foliage actor in target level
209
210 // Move instances to a foliage actor in target level
212
213 // Returns a map of Static Meshes and their placed instances attached to a component.
215
216 // Deletes the instances attached to a component
219
220 // Deletes the instances attached to a component, traverses all foliage actors in the world
222
223 // Deletes the instances spawned by a procedural component
227
231
232 // Finds a mesh entry or adds it if it doesn't already exist
234
236 // Add a new static mesh.
237 FOLIAGE_API FFoliageInfo* AddMesh(UStaticMesh* InMesh, UFoliageType** OutSettings = nullptr, const UFoliageType_InstancedStaticMesh* DefaultSettings = nullptr);
239
240 // Remove the FoliageType from the list, and all its instances.
242
243 // Select an individual instance.
245
246 // Select an individual instance.
247 FOLIAGE_API bool SelectInstance(AActor* InActor, bool bToggle);
248
249 //Get the bounds of all selected instances
251
252 // Whether actor has selected instances
254
255 // Will return all the foliage type used by currently selected instances
257
258 // Returns FoliageType associated to this FoliageInfo
260
261 // Will return all the foliage type used
263
264 // Propagate the selected instances to the actual foliage implementation
266
267 // Returns the location for the widget
268 FOLIAGE_API bool GetSelectionLocation(FBox& OutLocation) const;
269
272
273 /* Called to notify InstancedFoliageActor that a UFoliageType has been modified */
275 void NotifyFoliageTypeWillChange(UFoliageType* FoliageType);
276
279
280 /* Fix up a duplicate IFA */
282
284
285 UFUNCTION(BlueprintCallable, Category="Foliage", meta = (WorldContext = "WorldContextObject"))
286 static void AddInstances(UObject* WorldContextObject, UFoliageType* InFoliageType, const TArray<FTransform>& InTransforms);
287
288 UFUNCTION(BlueprintCallable, Category="Foliage", meta = (WorldContext = "WorldContextObject"))
289 static void RemoveAllInstances(UObject* WorldContextObject, UFoliageType* InFoliageType);
290#endif //WITH_EDITOR
291
292private:
293#if WITH_EDITORONLY_DATA
294 // Deprecated data, will be converted and cleaned up in PostLoad
297#endif//WITH_EDITORONLY_DATA
298
299#if WITH_EDITOR
300 void ClearSelection();
303
304 friend class UFoliageEditorSubsystem;
307
309
312
313 FOLIAGE_API void PostApplyLevelOffset(const FVector& InOffset, bool bWorldShift);
314 FOLIAGE_API void PostApplyLevelTransform(const FTransform& InTransform);
315#endif
316private:
317#if WITH_EDITOR
319#endif
320
321};
@ ForceInitToZero
Definition CoreMiscDefines.h:156
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:58
#define DECLARE_EVENT_OneParam(OwningType, EventName, Param1Type)
Definition DelegateCombinations.h:51
#define DECLARE_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:49
int32 FFoliageInstanceBaseId
Definition FoliageInstanceBase.h:11
#define FVector
Definition IOSSystemIncludes.h:8
TFunction< bool(const UPrimitiveComponent *)> FFoliageTraceFilterFunc
Definition InstancedFoliageActor.h:25
const T * GetDefault()
Definition UObjectGlobals.h:2155
@ Num
Definition MetalRHIPrivate.h:234
const bool
Definition NetworkReplayStreaming.h:178
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
const U & ObjectPtrDecay(const T &Value)
Definition ObjectPtr.h:1744
ETypedElementWorldType
Definition TypedElementWorldInterface.h:26
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Actor.h:257
Definition Controller.h:41
Definition ISMPartitionActor.h:21
Definition InstancedFoliageActor.h:29
const TMap< UFoliageType *, TUniqueObj< FFoliageInfo > > & GetFoliageInfos() const
Definition InstancedFoliageActor.h:47
virtual bool IsLevelBoundsRelevant() const override
Definition InstancedFoliageActor.h:67
Definition Archive.h:1208
Definition NameTypes.h:617
Definition UObjectGlobals.h:2492
Definition Text.h:385
Definition Foliage.Build.cs:6
Definition SMInstanceManager.h:26
Definition ArrayView.h:139
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition SubclassOf.h:30
Definition UniqueObj.h:13
Definition ActorComponent.h:152
Definition Class.h:3793
Definition FoliageType_InstancedStaticMesh.h:14
Definition FoliageType.h:106
Definition InstancedStaticMeshComponent.h:158
Definition Level.h:423
Definition Object.h:95
Definition ProceduralFoliageComponent.h:43
Definition StaticMesh.h:593
Definition World.h:918
FORCEINLINE T * Get(const FObjectPtr &ObjectPtr)
Definition ObjectPtr.h:426
ISMInstanceManager * GetSMInstanceManager(const FSMInstanceId &InstanceId)
Definition SMInstanceElementData.cpp:39
Definition InstancedFoliage.h:463
Definition InstancedFoliage.h:271
Definition InstancedFoliage.h:407
Definition InstancedFoliage.h:82
Definition Guid.h:109
Definition HitResult.h:21
Definition DamageEvents.h:129
Definition SMInstanceElementId.h:20