UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
LandscapeHeightfieldCollisionComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Misc/Guid.h"
9#include "EngineDefines.h"
13
14#include "LandscapeHeightfieldCollisionComponent.generated.h"
15
16class ALandscapeProxy;
18class ULandscapeComponent;
19class ULandscapeInfo;
22struct FConvexVolume;
23struct FEngineShowFlags;
25
26namespace Chaos
27{
28 class FHeightField;
29}
30
32{
33 None,
34 Simple,
35 Complex,
36 Editor
37};
38
39UCLASS(MinimalAPI, Within=LandscapeProxy)
41{
42 friend class FLandscapeHeightfieldCollisionComponentSceneProxy;
43
45
48
50 UPROPERTY()
51 TArray<TObjectPtr<ULandscapeLayerInfoObject>> ComponentLayerInfos;
52
54 UPROPERTY()
55 int32 SectionBaseX;
56
57 UPROPERTY()
58 int32 SectionBaseY;
59
61 UPROPERTY()
62 int32 CollisionSizeQuads;
63
65 UPROPERTY()
66 float CollisionScale;
67
69 UPROPERTY()
70 int32 SimpleCollisionSizeQuads;
71
72 bool bCookedCollisionDataWasDeleted = false;
73
75 UPROPERTY()
76 TArray<uint8> CollisionQuadFlags;
77
79 UPROPERTY()
80 FGuid HeightfieldGuid;
81
83 UPROPERTY()
84 FBox CachedLocalBox;
85
86#if WITH_EDITORONLY_DATA
88 UPROPERTY()
89 TLazyObjectPtr<ULandscapeComponent> RenderComponent_DEPRECATED;
90#endif // !WITH_EDITORONLY_DATA
91
92private:
94 UPROPERTY()
95 TObjectPtr<ULandscapeComponent> RenderComponentRef;
96
97public:
99 UFUNCTION(BlueprintCallable, Category = "Landscape")
100 LANDSCAPE_API ULandscapeComponent* GetRenderComponent() const;
101
119
120#if WITH_EDITORONLY_DATA
121 friend struct FEnableCollisionHashOptimScope;
122
123 UPROPERTY()
125
128
131
134
136 UPROPERTY()
137 TArray<TObjectPtr<UPhysicalMaterial>> PhysicalMaterialRenderObjects;
138
139 /* Cooked editor specific heightfield data, never serialized */
141
148
154
155#endif //WITH_EDITORONLY_DATA
156
162
164 UPROPERTY()
165 TArray<TObjectPtr<UPhysicalMaterial>> CookedPhysicalMaterials;
166
169
170 // local non-serialized ref counted pointers to keep the chaos heightfields alive between Unregister() and actual destruction of the component.
171 // this allows us to re-use them if the component gets a call to Register() again
172 Chaos::FHeightFieldPtr LocalHeightfieldGeometryRef;
173 Chaos::FHeightFieldPtr LocalHeightfieldSimpleGeometryRef;
174
176 int32 HeightfieldRowsCount;
177 int32 HeightfieldColumnsCount;
178 FNavHeightfieldSamples CachedHeightFieldSamples;
179
181 {
182 QF_PhysicalMaterialMask = 63, // Mask value for the physical material index, stored in the lower 6 bits.
183 QF_EdgeTurned = 64, // This quad's diagonal has been turned.
184 QF_NoCollision = 128, // This quad has no collision.
185 };
186
187#if WITH_EDITORONLY_DATA
188private:
189 bool bEnableCollisionHashOptim = false;
190#endif //WITH_EDITORONLY_DATA
191
192 //~ Begin UActorComponent Interface.
193protected:
194 virtual void OnCreatePhysicsState() override;
195 virtual void OnDestroyPhysicsState() override;
196public:
197
198 virtual void ApplyWorldOffset(const FVector& InOffset, bool bWorldShift) override;
199 //~ End UActorComponent Interface.
200
201 //~ Begin USceneComponent Interface.
202 virtual void DestroyComponent(bool bPromoteChildren = false) override;
203 virtual FBoxSphereBounds CalcBounds(const FTransform &BoundTransform) const override;
204
205 virtual ECollisionEnabled::Type GetCollisionEnabled() const override;
206 virtual ECollisionResponse GetCollisionResponseToChannel(ECollisionChannel Channel) const override;
207 virtual ECollisionChannel GetCollisionObjectType() const override;
208 virtual const FCollisionResponseContainer& GetCollisionResponseToChannels() const override;
209 virtual void OnRegister() override;
210 virtual void OnUnregister() override;
211 virtual bool AllowsAsyncPhysicsStateCreation() const override;
212 //~ End USceneComponent Interface.
213
214 //~ Begin UPrimitiveComponent Interface
215 virtual bool DoCustomNavigableGeometryExport(FNavigableGeometryExport& GeomExport) const override;
216 virtual bool IsShown(const FEngineShowFlags& ShowFlags) const override;
217 //End UPrimitiveComponent interface
218
219 //~ Begin INavRelevantInterface Interface
220 virtual bool SupportsGatheringGeometrySlices() const override { return true; }
221 virtual void GatherGeometrySlice(FNavigableGeometryExport& GeomExport, const FBox& SliceBox) const override;
222 virtual ENavDataGatheringMode GetGeometryGatheringMode() const override;
223 virtual void PrepareGeometryExportSync() override;
224 //~ End INavRelevantInterface Interface
225
226 //~ Begin UObject Interface.
227 virtual void Serialize(FArchive& Ar) override;
228 virtual void BeginDestroy() override;
229 virtual void GetResourceSizeEx(FResourceSizeEx& CumulativeResourceSize) override;
230 virtual void PostLoad() override;
231 virtual void PreSave(FObjectPreSaveContext ObjectSaveContext) override;
232#if WITH_EDITOR
233 virtual bool NeedsLoadForClient() const override;
234 virtual bool NeedsLoadForServer() const override;
235 virtual void ExportCustomProperties(FOutputDevice& Out, uint32 Indent) override;
236 virtual void ImportCustomProperties(const TCHAR* SourceText, FFeedbackContext* Warn) override;
237 //~ End UObject Interface.
238
241
246 virtual bool CookCollisionData(const FName& Format, bool bUseDefaultMaterialOnly, bool bCheckDDC, TArray<uint8>& OutCookedData, TArray<UPhysicalMaterial*>& InOutMaterials) const;
247
250
252 virtual uint32 ComputeCollisionHash() const;
253#endif
254
256 {
257 int32 CollisionSizeVerts = 0;
258 int32 SimpleCollisionSizeVerts = 0;
259 int32 NumSamples = 0;
260 int32 NumSimpleSamples = 0;
261 };
262 FCollisionSampleInfo GetCollisionSampleInfo() const;
263
279
280#if WITH_EDITOR
281 // Set up params to call WriteRuntimeData using editor data members.
282 FWriteRuntimeDataParams MakeWriteRuntimeDataParams(bool bUseDefaultMaterialOnly) const;
283#endif
284
285 // Writes to a cooked data buffer using raw heightfield data
287
289
291 ULandscapeInfo* GetLandscapeInfo() const;
292
293#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST) && WITH_EDITORONLY_DATA
294 // The scene proxy is only for debug purposes :
295 virtual FPrimitiveSceneProxy* CreateSceneProxy() override;
296#endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST) && WITH_EDITORONLY_DATA
297
299 virtual void CreateCollisionObject();
300
302 LANDSCAPE_API void CreateCollisionObject(
303 bool bUseDefaultMaterialOnly,
307
309 LANDSCAPE_API ALandscapeProxy* GetLandscapeProxy() const;
310
312 LANDSCAPE_API FIntPoint GetSectionBase() const;
313
315 LANDSCAPE_API void SetSectionBase(FIntPoint InSectionBase);
316
318 LANDSCAPE_API virtual bool RecreateCollision();
319
320private:
321 // @todo(chaos): remove when implicit objects are ref counted
322 void DeferredDestroyCollision(const TRefCountPtr<FHeightfieldGeometryRef>& HeightfieldRefLifetimeExtender);
323public:
324
325#if WITH_EDITORONLY_DATA
326 // Called from editor code to manage foliage instances on landscape.
328
330#endif
331
332 void SetRenderComponent(ULandscapeComponent* InRenderComponent) { RenderComponentRef = InRenderComponent; }
333
334public:
336 LANDSCAPE_API UPhysicalMaterial* GetPhysicalMaterial(float X, float Y, EHeightfieldSource HeightFieldSource);
337
342 LANDSCAPE_API bool FillHeightTile(TArrayView<float> Heights, int32 Offset, int32 Stride) const;
343 LANDSCAPE_API bool FillMaterialIndexTile(TArrayView<uint8> Materials, int32 Offset, int32 Stride) const;
344};
345
346
347
@ INDEX_NONE
Definition CoreMiscDefines.h:150
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
ECollisionChannel
Definition EngineTypes.h:1088
ECollisionResponse
Definition EngineTypes.h:1240
#define X(Name, Desc)
Definition FormatStringSan.h:47
EHeightfieldSource
Definition LandscapeHeightfieldCollisionComponent.h:32
ENavDataGatheringMode
Definition NavDataGatheringMode.h:9
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
uint32 Offset
Definition VulkanMemory.cpp:4033
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition FeedbackContext.h:30
Definition NameTypes.h:617
Definition ObjectSaveContext.h:244
Definition OutputDevice.h:133
Definition PrimitiveSceneProxy.h:296
Definition RefCounting.h:283
Definition ObjectMacros.h:180
Definition Landscape.Build.cs:7
Definition ArrayView.h:139
Definition Array.h:670
Definition BulkData.h:1036
Definition SharedPointer.h:692
Definition LandscapeHeightfieldCollisionComponent.h:41
virtual bool SupportsGatheringGeometrySlices() const override
Definition LandscapeHeightfieldCollisionComponent.h:220
void SetRenderComponent(ULandscapeComponent *InRenderComponent)
Definition LandscapeHeightfieldCollisionComponent.h:332
ECollisionQuadFlags
Definition LandscapeHeightfieldCollisionComponent.h:181
TArray< uint8 > CookedCollisionData
Definition LandscapeHeightfieldCollisionComponent.h:161
Definition LandscapeInfo.h:109
Definition LandscapeLayerInfoObject.h:60
Definition PhysicalMaterial.h:104
Definition SkeletalMeshComponent.h:307
Type
Definition EngineTypes.h:1573
@ false
Definition radaudio_common.h:23
Definition EngineTypes.h:1339
Definition ConvexVolume.h:44
Definition ShowFlags.h:56
Definition Guid.h:109
Definition NavigationTypes.h:741
Definition NavigationSystemHelpers.h:25
Definition ResourceSize.h:31
Definition LazyObjectPtr.h:230
Definition ObjectPtr.h:488
Definition Optional.h:131
Definition BoxSphereBounds.h:25
Definition IntPoint.h:25
Definition LandscapeHeightfieldCollisionComponent.h:256
Definition LandscapeHeightfieldCollisionComponent.h:103
Chaos::FHeightFieldPtr HeightfieldGeometry
Definition LandscapeHeightfieldCollisionComponent.h:107
FGuid Guid
Definition LandscapeHeightfieldCollisionComponent.h:104
TArray< Chaos::FMaterialHandle > UsedChaosMaterials
Definition LandscapeHeightfieldCollisionComponent.h:106
Chaos::FHeightFieldPtr HeightfieldSimpleGeometry
Definition LandscapeHeightfieldCollisionComponent.h:108
Definition LandscapeHeightfieldCollisionComponent.h:265
TArrayView< const uint16 > Heights
Definition LandscapeHeightfieldCollisionComponent.h:269
TArrayView< const uint8 > SimpleDominantLayers
Definition LandscapeHeightfieldCollisionComponent.h:272
TArrayView< const uint8 > SimpleRenderPhysicalMaterialIds
Definition LandscapeHeightfieldCollisionComponent.h:274
TArrayView< const TObjectPtr< ULandscapeLayerInfoObject > > ComponentLayerInfos
Definition LandscapeHeightfieldCollisionComponent.h:276
TArrayView< const uint16 > SimpleHeights
Definition LandscapeHeightfieldCollisionComponent.h:270
TArrayView< const uint8 > DominantLayers
Definition LandscapeHeightfieldCollisionComponent.h:271
TArrayView< const uint8 > RenderPhysicalMaterialIds
Definition LandscapeHeightfieldCollisionComponent.h:273
TArrayView< const TObjectPtr< UPhysicalMaterial > > PhysicalMaterialRenderObjects
Definition LandscapeHeightfieldCollisionComponent.h:275