UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ComponentInterfaces.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Containers/Array.h"
8
9class UWorld;
10class FSceneInterface;
12class UStaticMesh;
15class HHitProxy;
16
43
51
57
59{
60public:
61 virtual bool IsRenderStateCreated() const = 0;
62 virtual bool IsRenderStateDirty() const = 0;
63 virtual bool ShouldCreateRenderState() const = 0;
64 virtual bool IsRegistered() const = 0;
65 virtual bool IsUnreachable() const = 0;
66 virtual UWorld* GetWorld() const = 0;
67 virtual FSceneInterface* GetScene() const = 0;
68 virtual FPrimitiveSceneProxy* GetSceneProxy() const = 0;
70 virtual void MarkRenderStateDirty() = 0;
71 virtual void DestroyRenderState() = 0;
73 virtual FString GetName() const = 0;
74 virtual FString GetFullName() const = 0;
75 virtual FTransform GetTransform() const = 0;
76 virtual FBoxSphereBounds GetBounds() const = 0;
77 virtual float GetLastRenderTimeOnScreen() const = 0;
79 virtual UObject* GetUObject() = 0;
80 virtual const UObject* GetUObject() const = 0;
81 virtual void PrecachePSOs() = 0;
82
83 // helper to obtain typed UObjects
84 template<class T>
85 inline const T* GetUObject() const { return Cast<T>(GetUObject()); }
86
87 template<class T>
88 inline T* GetUObject() { return Cast<T>(GetUObject()); }
89
90 virtual UObject* GetOwner() const = 0;
91
92 // helper to have typed owners
93 template<class T>
94 inline T* GetOwner() { return Cast<T>(GetOwner()); }
95
96 virtual FString GetOwnerName() const = 0;
99#if WITH_EDITOR
100 virtual HHitProxy* CreateMeshHitProxy(int32 SectionIndex, int32 MaterialIndex) = 0;
101#endif
103
106protected:
107
108 template<class T>
110
112};
113
115{
116public:
117#if WITH_EDITOR
118 virtual void OnMeshRebuild(bool bRenderDataChanged) = 0;
119 virtual void PreStaticMeshCompilation() = 0;
120 virtual void PostStaticMeshCompilation() = 0;
121#endif
122 virtual UStaticMesh* GetStaticMesh() const = 0;
123
126 {
127 // use the non-const version and return it as a const object to avoid duplicating the code in implementers
128 return (const_cast<IStaticMeshComponent*>(this))->GetPrimitiveComponentInterface();
129 }
130
133
134protected:
135
136 template<class T>
138
140
141};
142
143
144#pragma region HelperMacros
145
146// These macros are intended to allow implementing an interface with same memory footprint/performance as inheriting from
147// the abstract base class, but without mixing the interface methods with the class methods.
148//
149// It declares a member for the interface and utility functions in the host class to get the host ptr from the interface instance.
150// And thus allow declaration of the interface inside a class without requiring the interface to host a back ptr to it's owner.
151//
152//
153// Example...
154//
155// class FActorSomeInteface : ISomeInterface
156// {
157// // Nothing but the overrides
158// virtual void OverrideSomething() override;
159// };
160//
161// class UHostClass
162// {
163// UE_ComponentInterfaceDeclaration(SomeInterface, FActor);
164// }
165//
166// void FActorSomeInterface::OverrideSomething()
167// {
168// UHostClass::GetHostClass(this)->OverrideSomethingImplementer();
169// }
170//
171
172
173
174#define UE_DECLARE_COMPONENT_INTERFACE_INTERNAL(actorcomponenttype, componentinterfacetype, actorcomponentinterfacetype, actorcomponentinterfacemember, interfacename )\
175 public:\
176 componentinterfacetype* Get##interfacename ##Interface() const { return (componentinterfacetype*)&actorcomponentinterfacemember; } \
177 protected: \
178 actorcomponentinterfacetype actorcomponentinterfacemember;\
179 \
180 static actorcomponenttype* Get##interfacename(actorcomponentinterfacetype* InImpl)\
181 {\
182 return (actorcomponenttype*)(((size_t)InImpl) - offsetof(actorcomponenttype, actorcomponentinterfacemember));\
183 }\
184 static const actorcomponenttype* Get##interfacename(const actorcomponentinterfacetype* InImpl)\
185 {\
186 return (const actorcomponenttype*)(((size_t)InImpl) - offsetof(actorcomponenttype, actorcomponentinterfacemember));\
187 }\
188 friend class actorcomponentinterfacetype;
189
190
191#define UE_DECLARE_COMPONENT_INTERFACE(name, baseprefix) UE_DECLARE_COMPONENT_INTERFACE_INTERNAL(U##name, I##name , PREPROCESSOR_JOIN(PREPROCESSOR_JOIN(baseprefix, name), Interface), PREPROCESSOR_JOIN(name, Interface), name)
192
193#define UE_DECLARE_COMPONENT_ACTOR_INTERFACE(name) UE_DECLARE_COMPONENT_INTERFACE(name, FActor)
194
195#pragma endregion
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
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
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition PrimitiveSceneProxy.h:296
Definition ActorComponent.h:47
Definition SceneInterface.h:106
Definition HitProxies.h:135
Definition ComponentInterfaces.h:59
virtual UObject * GetUObject()=0
virtual FString GetName() const =0
T * GetUObject()
Definition ComponentInterfaces.h:88
virtual FBoxSphereBounds GetBounds() const =0
T * GetOwner()
Definition ComponentInterfaces.h:94
static ENGINE_API void RemoveImplementer(const UClass *ImplementerClass)
Definition ComponentInterfaces.cpp:15
virtual const UObject * GetUObject() const =0
virtual FString GetFullName() const =0
virtual bool IsUnreachable() const =0
virtual bool IsRegistered() const =0
virtual FPrimitiveSceneProxy * CreateSceneProxy()=0
virtual bool IsRenderStateDirty() const =0
virtual HHitProxy * CreatePrimitiveHitProxies(TArray< TRefCountPtr< HHitProxy > > &OutHitProxies)=0
virtual float GetLastRenderTimeOnScreen() const =0
static ENGINE_API TArray< FComponentInterfaceImplementation > Implementers
Definition ComponentInterfaces.h:111
virtual FString GetOwnerName() const =0
virtual void GetStreamableRenderAssetInfo(TArray< struct FStreamingRenderAssetPrimitiveInfo > &StreamableRenderAssets) const =0
virtual void MarkRenderStateDirty()=0
virtual FTransform GetTransform() const =0
virtual void GetPrimitiveStats(FPrimitiveStats &PrimitiveStats) const =0
virtual void GetUsedMaterials(TArray< UMaterialInterface * > &OutMaterials, bool bGetDebugMaterials=false) const =0
const T * GetUObject() const
Definition ComponentInterfaces.h:85
virtual UObject * GetOwner() const =0
virtual void DestroyRenderState()=0
static ENGINE_API void AddImplementer(const FComponentInterfaceImplementation &Implementer)
Definition ComponentInterfaces.cpp:10
virtual FPrimitiveSceneProxy * GetSceneProxy() const =0
virtual void PrecachePSOs()=0
virtual FSceneInterface * GetScene() const =0
virtual UWorld * GetWorld() const =0
virtual bool IsRenderStateCreated() const =0
virtual bool ShouldCreateRenderState() const =0
virtual void CreateRenderState(FRegisterComponentContext *Context)=0
Definition ComponentInterfaces.h:115
const IPrimitiveComponent * GetPrimitiveComponentInterface() const
Definition ComponentInterfaces.h:125
virtual UStaticMesh * GetStaticMesh() const =0
virtual IPrimitiveComponent * GetPrimitiveComponentInterface()=0
static ENGINE_API TArray< FComponentInterfaceImplementation > Implementers
Definition ComponentInterfaces.h:139
static ENGINE_API void RemoveImplementer(const UClass *ImplementerClass)
Definition ComponentInterfaces.cpp:33
static ENGINE_API void AddImplementer(const FComponentInterfaceImplementation &Implementer)
Definition ComponentInterfaces.cpp:28
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
Definition ComponentInterfaceIterator.h:10
Definition AndroidPlatformMisc.h:14
Definition RefCounting.h:454
Definition Class.h:3793
Definition MaterialInterface.h:296
Definition Object.h:95
Definition StaticMesh.h:593
Definition World.h:918
Definition ComponentInterfaces.h:53
TFunction< void *(UObject *)> Resolver
Definition ComponentInterfaces.h:55
UClass * Class
Definition ComponentInterfaces.h:54
Definition ComponentInterfaces.h:18
bool bIsOptionalLOD
Definition ComponentInterfaces.h:22
FPrimitiveLODStats(const FPrimitiveLODStats &Other)=default
FPrimitiveLODStats(int32 InLOD)
Definition ComponentInterfaces.h:27
int32 LODIndex
Definition ComponentInterfaces.h:19
TArray< uint16 > MaterialIndices
Definition ComponentInterfaces.h:25
FPrimitiveLODStats & operator=(FPrimitiveLODStats &&RHS)=default
int32 GetDrawCount() const
Definition ComponentInterfaces.h:38
bool bIsAvailable
Definition ComponentInterfaces.h:23
FPrimitiveLODStats(FPrimitiveLODStats &&Other)=default
uint32 Sections
Definition ComponentInterfaces.h:20
SIZE_T TotalResourceSize
Definition ComponentInterfaces.h:24
uint32 Triangles
Definition ComponentInterfaces.h:21
FPrimitiveLODStats & operator=(const FPrimitiveLODStats &RHS)=default
Definition ComponentInterfaces.h:48
TArray< FPrimitiveLODStats > LODStats
Definition ComponentInterfaces.h:49
Definition BoxSphereBounds.h:25