UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MassTypeManager.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "UObject/Class.h"
6#include "UObject/ObjectKey.h"
7#include "Misc/NotNull.h"
8#include "Misc/TVariant.h"
10#include "MassEntityConcepts.h"
12#include "MassEntityRelations.h"
14
15#define UE_API MASSENTITY_API
16
17
19
20namespace UE::Mass
21{
22 using namespace Relations;
23 struct FRelationData;
24
27 {
28 FTypeHandle() = default;
29 FTypeHandle(const FTypeHandle&) = default;
30
31 bool operator==(const FTypeHandle&) const = default;
32
33 bool IsValid() const;
34
35 const UClass* GetClass() const
36 {
37 return Cast<const UClass>(TypeKey.ResolveObjectPtr());
38 }
39
41 {
42 return Cast<UScriptStruct>(TypeKey.ResolveObjectPtr());
43 }
44
45 friend inline uint32 GetTypeHash(const FTypeHandle& InHandle)
46 {
47 return GetTypeHash(InHandle.TypeKey);
48 }
49
51 {
52 const UStruct* RepresentedType = TypeKey.ResolveObjectPtr();
54 }
55
56 FString ToString() const
57 {
58 const UStruct* RepresentedType = TypeKey.ResolveObjectPtr();
60 }
61
62 private:
63 friend struct FTypeManager;
65
67 };
68
71 {
72 };
73
76 {
78
80 template <typename T>
88
90 bool bGameThreadOnly = true;
92 bool bThreadSafeWrite = false;
93 };
94
97 {
99
101 template<CSharedFragment T>
108
110 bool bGameThreadOnly = true;
111 };
112
139
140 struct FTypeManager : TSharedFromThis<FTypeManager>
141 {
143
145
147
151 bool IsEmpty() const;
152
159
161 template<CSharedFragment T>
163
167
172
176 const FTypeInfo* GetTypeInfo(TObjectKey<const UStruct> TypeKey) const;
177
182
185
191 using FSubsystemTypeConstIterator = TSet<FTypeHandle>::TConstIterator;
192
195
197
199
205
206 private:
209
210 FMassEntityManager& OuterEntityManager;
211
214
216 TSet<FTypeHandle> SubsystemTypes;
217
218 bool bBuiltInTypesRegistered = false;
219 };
220
221 //----------------------------------------------------------------------------
222 // INLINES
223 //----------------------------------------------------------------------------
224 inline bool FTypeHandle::IsValid() const
225 {
226 // using this strange contraption since TObjectKey doesn't supply a way to check
227 // whether it's set, while comparison and construction is trivial.
228 // Note: we don't care to what the key's been set, we don't expect types to go away
229 return TypeKey != TObjectKey<const UStruct>();
230 }
231
236
241
246
251
252 inline bool FTypeManager::IsEmpty() const
253 {
254 return TypeDataMap.IsEmpty();
255 }
256
261
266
267 template<CSharedFragment T>
269 {
270 return RegisterType(T::StaticStruct(), FSharedFragmentTypeTraits::Make<T>());
271 }
272
273 template<typename T>
276 {
277 return RegisterType(T::StaticClass(), FSubsystemTypeTraits::Make<T>());
278 }
279
281 {
282 return TypeDataMap.Find(TypeHandle);
283 }
284
286 {
287 return TypeDataMap.Find(FTypeHandle(TypeKey));
288 }
289
291 {
294 return RelationInfo->GetAsRelationTraitsChecked();
295 }
296
301
303 {
304 return OuterEntityManager;
305 }
306
311}
312
313#undef UE_API
#define check(expr)
Definition AssertionMacros.h:314
FName GetFNameSafe(const FField *InField)
Definition Field.h:1216
FString GetNameSafe(const FField *InField)
Definition Field.h:1230
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
T TNotNull
Definition NotNull.h:307
#define UE_API
Definition SColorGradingComponentViewer.h:12
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition UnrealString.h.inl:34
Definition ObjectKey.h:228
InElementType * ResolveObjectPtr() const
Definition ObjectKey.h:291
Definition SharedPointer.h:1640
U & Get() UE_LIFETIMEBOUND
Definition TVariant.h:146
U * TryGet() UE_LIFETIMEBOUND
Definition TVariant.h:174
Definition Class.h:3793
Definition Class.h:1720
Definition Class.h:480
Definition Subsystem.h:48
Definition MassArchetypeData.h:21
Definition MassEntityManager.h:96
Definition UnrealTypeTraits.h:40
Definition MassExternalSubsystemTraits.h:27
Definition MassExternalSubsystemTraits.h:44
Definition MassTypeManager.h:71
Definition MassTypeManager.h:97
static FSharedFragmentTypeTraits Make()
Definition MassTypeManager.h:102
bool bGameThreadOnly
Definition MassTypeManager.h:110
Definition MassTypeManager.h:76
static FSubsystemTypeTraits Make()
Definition MassTypeManager.h:81
bool bGameThreadOnly
Definition MassTypeManager.h:90
bool bThreadSafeWrite
Definition MassTypeManager.h:92
Definition MassTypeManager.h:27
const UScriptStruct * GetScriptStruct() const
Definition MassTypeManager.h:40
FName GetFName() const
Definition MassTypeManager.h:50
FTypeHandle(const FTypeHandle &)=default
FString ToString() const
Definition MassTypeManager.h:56
bool IsValid() const
Definition MassTypeManager.h:224
const UClass * GetClass() const
Definition MassTypeManager.h:35
friend uint32 GetTypeHash(const FTypeHandle &InHandle)
Definition MassTypeManager.h:45
bool operator==(const FTypeHandle &) const =default
Definition MassTypeManager.h:118
FTypeTraits Traits
Definition MassTypeManager.h:125
const FSharedFragmentTypeTraits * GetAsSharedFragmentTraits() const
Definition MassTypeManager.h:237
FName TypeName
Definition MassTypeManager.h:124
const FSubsystemTypeTraits * GetAsSystemTraits() const
Definition MassTypeManager.h:232
const FRelationTypeTraits & GetAsRelationTraitsChecked() const
Definition MassTypeManager.h:247
const FRelationTypeTraits * GetAsRelationTraits() const
Definition MassTypeManager.h:242
Definition MassTypeManager.h:141
bool IsEmpty() const
Definition MassTypeManager.h:252
FTypeHandle RegisterType()
Definition MassTypeManager.h:268
FTypeInfoConstIterator MakeIterator() const
Definition MassTypeManager.h:257
DECLARE_MULTICAST_DELEGATE_OneParam(FOnRegisterBuiltInTypes, FTypeManager &)
UE_API FTypeHandle GetRelationTypeHandle(const TNotNull< const UScriptStruct * > RelationOrElementType) const
Definition MassTypeManager.cpp:130
const FTypeInfo * GetTypeInfo(FTypeHandle TypeHandle) const
Definition MassTypeManager.h:280
TMap< FTypeHandle, FTypeInfo >::TConstIterator FTypeInfoConstIterator
Definition MassTypeManager.h:184
TSet< FTypeHandle >::TConstIterator FSubsystemTypeConstIterator
Definition MassTypeManager.h:191
void RegisterBuiltInTypes()
Definition MassTypeManager.cpp:32
::Value FTypeHandle RegisterType()
static UE_API FOnRegisterBuiltInTypes OnRegisterBuiltInTypes
Definition MassTypeManager.h:204
FMassEntityManager & GetEntityManager()
Definition MassTypeManager.h:302
UE_API bool IsValidRelationType(const TNotNull< const UScriptStruct * > RelationOrElementType) const
Definition MassTypeManager.cpp:140
const FRelationTypeTraits & GetRelationTypeChecked(const FTypeHandle TypeHandle) const
Definition MassTypeManager.h:290
static FTypeHandle MakeTypeHandle(TNotNull< const UStruct * > InTypeKey)
Definition MassTypeManager.h:307
FSubsystemTypeConstIterator MakeSubsystemIterator() const
Definition MassTypeManager.h:262
Definition MassEntityRelations.h:105