UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MassEntityView.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "MassEntityHandle.h"
7#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
9#endif // UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
10#include "MassEntityView.generated.h"
11
12#define UE_API MASSENTITY_API
13
17
22USTRUCT()
24{
26
27 FMassEntityView() = default;
28
35 UE_API FMassEntityView(const FMassArchetypeHandle& ArchetypeHandle, FMassEntityHandle Entity);
36
41 UE_API FMassEntityView(const FMassEntityManager& EntityManager, FMassEntityHandle Entity);
42
47 static UE_API FMassEntityView TryMakeView(const FMassEntityManager& EntityManager, FMassEntityHandle Entity);
48
49 FMassEntityHandle GetEntity() const { return Entity; }
50
52 template<typename T>
53 T& GetFragmentData() const
54 {
55 static_assert(!UE::Mass::CTag<T>,
56 "Given struct doesn't represent a valid fragment type but a tag. Use HasTag instead.");
58
59 return *((T*)GetFragmentPtrChecked(*T::StaticStruct()));
60 }
61
63 template<typename T>
65 {
66 static_assert(!UE::Mass::CTag<T>,
67 "Given struct doesn't represent a valid fragment type but a tag. Use HasTag instead.");
69
70 return (T*)GetFragmentPtr(*T::StaticStruct());
71 }
72
74 {
75 check(FragmentType);
76 return FStructView(FragmentType, static_cast<uint8*>(GetFragmentPtr(*FragmentType)));
77 }
78
80 template<typename T>
82 {
84 "Given struct doesn't represent a valid const shared fragment type. Make sure to inherit from FMassConstSharedFragment or one of its child-types.");
85
86 return (const T*)GetConstSharedFragmentPtr(*T::StaticStruct());
87 }
88
90 template<typename T>
92 {
94 "Given struct doesn't represent a valid const shared fragment type. Make sure to inherit from FMassConstSharedFragment or one of its child-types.");
95
96 return *((const T*)GetConstSharedFragmentPtrChecked(*T::StaticStruct()));
97 }
98
100 {
102 return FConstStructView(FragmentType, static_cast<const uint8*>(GetConstSharedFragmentPtr(*FragmentType)));
103 }
104
106 template<UE::Mass::CSharedFragment T>
108 {
109 return *((T*)GetSharedFragmentPtrChecked(*T::StaticStruct()));
110 }
111
113 template<UE::Mass::CSharedFragment T>
115 {
116 return (T*)GetSharedFragmentPtr(*T::StaticStruct());
117 }
118
119 template<UE::Mass::CConstSharedFragment T>
120 UE_DEPRECATED(5.5, "Using GetSharedFragmentDataPtr with const shared fragments is deprecated. Use GetConstSharedFragmentDataPtr instead")
121 T* GetSharedFragmentDataPtr() const
122 {
123 return const_cast<T*>(GetConstSharedFragmentDataPtr<T>());
124 }
125
126 template<UE::Mass::CConstSharedFragment T>
127 UE_DEPRECATED(5.5, "Using GetSharedFragmentDataPtr with const shared fragments is deprecated. Use GetConstSharedFragmentData instead")
128 T& GetSharedFragmentData() const
129 {
130 return const_cast<T&>(GetConstSharedFragmentData<T>());
131 }
132
134 {
136 return FStructView(FragmentType, static_cast<uint8*>(GetSharedFragmentPtr(*FragmentType)));
137 }
138
139 template<typename T>
140 bool HasTag() const
141 {
142 static_assert(UE::Mass::CTag<T>, "Given struct doesn't represent a valid tag type. Make sure to inherit from FMassTag or one of its child-types.");
143 return HasTag(*T::StaticStruct());
144 }
145
146 UE_API bool HasTag(const UScriptStruct& TagType) const;
147
148 bool IsSet() const;
149 bool IsValid() const;
150 bool operator==(const FMassEntityView& Other) const;
151
152protected:
153 UE_API void* GetFragmentPtr(const UScriptStruct& FragmentType) const;
154 UE_API void* GetFragmentPtrChecked(const UScriptStruct& FragmentType) const;
155 UE_API const void* GetConstSharedFragmentPtr(const UScriptStruct& FragmentType) const;
156 UE_API const void* GetConstSharedFragmentPtrChecked(const UScriptStruct& FragmentType) const;
157 UE_API void* GetSharedFragmentPtr(const UScriptStruct& FragmentType) const;
158 UE_API void* GetSharedFragmentPtrChecked(const UScriptStruct& FragmentType) const;
159
160private:
161 FMassEntityHandle Entity;
162 FMassEntityInChunkDataHandle EntityDataHandle;
163 FMassArchetypeData* Archetype = nullptr;
164};
165
166//-----------------------------------------------------------------------------
167// INLINES
168//-----------------------------------------------------------------------------
169inline bool FMassEntityView::IsSet() const
170{
171 return EntityDataHandle.IsValid(Archetype);
172}
173
174inline bool FMassEntityView::IsValid() const
175{
176 return IsSet();
177}
178
180{
181 return Archetype == Other.Archetype && EntityDataHandle == Other.EntityDataHandle;
182}
183
184#undef UE_API
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define MASS_INVALID_FRAGMENT_MSG
Definition MassEntityElementTypes.h:16
#define UE_API
Definition MassEntityView.h:12
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Class.h:1720
Definition MassEntityConcepts.h:32
Definition MassEntityConcepts.h:16
Definition MassEntityConcepts.h:23
bool IsA< FMassSharedFragment >(const UStruct *Struct)
Definition MassEntityElementTypes.h:73
bool IsA< FMassConstSharedFragment >(const UStruct *Struct)
Definition MassEntityElementTypes.h:79
Definition StructView.h:217
Definition MassArchetypeData.h:172
Definition MassArchetypeTypes.h:39
bool operator==(const FMassArchetypeHandle &Other) const
Definition MassArchetypeTypes.h:368
Definition MassEntityHandle.h:13
Definition MassArchetypeTypes.h:304
MASSENTITY_API bool IsValid(const FMassArchetypeData *ArchetypeData) const
Definition MassArchetypeTypes.cpp:482
Definition MassEntityManager.h:96
Definition MassEntityView.h:24
T * GetFragmentDataPtr() const
Definition MassEntityView.h:64
T & GetSharedFragmentData() const
Definition MassEntityView.h:107
FStructView GetSharedFragmentDataStruct(const UScriptStruct *FragmentType) const
Definition MassEntityView.h:133
bool IsSet() const
Definition MassEntityView.h:169
const T * GetConstSharedFragmentDataPtr() const
Definition MassEntityView.h:81
bool operator==(const FMassEntityView &Other) const
Definition MassEntityView.h:179
FStructView GetFragmentDataStruct(const UScriptStruct *FragmentType) const
Definition MassEntityView.h:73
T & GetFragmentData() const
Definition MassEntityView.h:53
bool IsValid() const
Definition MassEntityView.h:174
bool HasTag() const
Definition MassEntityView.h:140
FConstStructView GetConstSharedFragmentDataStruct(const UScriptStruct *FragmentType) const
Definition MassEntityView.h:99
const T & GetConstSharedFragmentData() const
Definition MassEntityView.h:91
T * GetSharedFragmentDataPtr() const
Definition MassEntityView.h:114
Definition StructView.h:24