UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MassDebugger.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
6#include "MassEntityTrace.h"
7#if WITH_MASSENTITY_DEBUG
10#include "MassEntityQuery.h"
11#include "MassProcessor.h"
14#include "UObject/ObjectKey.h"
15#if UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
17#endif // UE_ENABLE_INCLUDE_ORDER_DEPRECATED_IN_5_6
18
19class FOutputDevice;
20class FStructOnScope;
21class UMassProcessor;
22struct FMassEntityQuery;
28enum class EMassFragmentAccess : uint8;
29enum class EMassFragmentPresence : uint8;
30#endif // WITH_MASSENTITY_DEBUG
31#include "MassDebugger.generated.h"
32
33namespace UE::Mass::Debug
34{
50
52} // namespace UE::Mass::Debug
53
54USTRUCT()
56{
58 explicit FMassGenericDebugEvent(const UObject* InContext = nullptr)
59#if WITH_EDITORONLY_DATA
61#endif // WITH_EDITORONLY_DATA
62 {
63 }
64
65#if WITH_EDITORONLY_DATA
66 // note that it's not a uproperty since these events are only intended to be used instantly, never stored
67 const UObject* Context = nullptr;
68#endif // WITH_EDITORONLY_DATA
69};
70
71#if WITH_MASSENTITY_DEBUG
72
73namespace UE::Mass::Debug
74{
79} // namespace UE::Mass::Debug
80
81#define MASS_IF_ENTITY_DEBUGGED(Manager, EntityHandle) (FMassDebugger::GetSelectedEntity(Manager) == EntityHandle)
82#define MASS_BREAK_IF_ENTITY_DEBUGGED(Manager, EntityHandle) { if (UE::Mass::Debug::bAllowBreakOnDebuggedEntity && MASS_IF_ENTITY_DEBUGGED(Manager, EntityHandle)) { PLATFORM_BREAK();} }
83#define MASS_BREAK_IF_ENTITY_INDEX(EntityHandle, InIndex) { if (UE::Mass::Debug::bAllowBreakOnDebuggedEntity && EntityHandle.Index == InIndex) { PLATFORM_BREAK();} }
84#define MASS_SET_ENTITY_DEBUGGED(Manager, EntityHandle) { if (UE::Mass::Debug::bAllowProceduralDebuggedEntitySelection) {FMassDebugger::SelectEntity(Manager, EntityHandle); }}
85
87{
88 Error,
89 Warning,
90 Info,
91 // the following two need to remain last
92 Default,
93 MAX = Default
94};
95
96namespace UE::Mass::Debug
97{
99 {
104 const FMassTagBitSet& RequiredAllTags;
105 const FMassTagBitSet& RequiredAnyTags;
106 const FMassTagBitSet& RequiredNoneTags;
107 const FMassTagBitSet& RequiredOptionalTags;
108 const FMassExternalSubsystemBitSet& RequiredConstSubsystems;
109 const FMassExternalSubsystemBitSet& RequiredMutableSubsystems;
110 };
111
113 MASSENTITY_API extern void DebugOutputDescription(TConstArrayView<UMassProcessor*> Processors, FOutputDevice& Ar);
114
115 MASSENTITY_API extern bool HasDebugEntities();
117
126
128 {
129 static constexpr EMessageSeverity::Type ConversionMap[int(EMassDebugMessageSeverity::MAX)] =
130 {
131 /*EMassDebugMessageSeverity::Error=*/EMessageSeverity::Error,
132 /*EMassDebugMessageSeverity::Warning=*/EMessageSeverity::Warning,
133 /*EMassDebugMessageSeverity::Info=*/EMessageSeverity::Info
134 };
135 return MassSeverity == EMassDebugMessageSeverity::Default
138 }
139} // namespace UE::Mass::Debug
140
141struct FMassDebugger
142{
143 struct FEnvironment
144 {
150
151 bool bHasBreakpoint = false;
152
154
156
160
161#if UE_MASS_TRACE_ENABLED
163#endif
164
167
168 bool IsValid() const { return EntityManager.IsValid(); }
169
170 void ClearBreakpoints();
171 };
172
177 DECLARE_TS_MULTICAST_DELEGATE_ThreeParams(FOnDebugEvent, const FName /*EventName*/, FConstStructView /*Payload*/, const EMassDebugMessageSeverity /*SeverityOverride*/);
178
183
184 static MASSENTITY_API UE::Mass::Debug::FQueryRequirementsView GetQueryRequirements(const FMassEntityQuery& Query);
187
188 static MASSENTITY_API void ForEachArchetype(const FMassEntityManager& EntityManager, const UE::Mass::Debug::FArchetypeFunction& Function);
190 static MASSENTITY_API const FMassArchetypeCompositionDescriptor& GetArchetypeComposition(const FMassArchetypeHandle& ArchetypeHandle);
191
193 static MASSENTITY_API uint64 GetArchetypeTraceID(const FMassArchetypeHandle& ArchetypeHandle);
194
197 const FMassArchetypeChunk& Chunk);
198
199 static MASSENTITY_API const FMassArchetypeData* GetArchetypeData(const FMassArchetypeHandle& ArchetypeHandle);
200 static MASSENTITY_API void EnumerateChunks(const FMassArchetypeData& Archetype, TFunctionRef<void(const FMassArchetypeChunk&)> Fn);
201
205
208
210 static MASSENTITY_API FString GetRequirementsDescription(const FMassFragmentRequirements& Requirements);
213
215 static MASSENTITY_API void OutputEntityDescription(FOutputDevice& Ar, const FMassEntityManager& EntityManager, const int32 EntityIndex, const TCHAR* InPrefix = TEXT(""));
216 static MASSENTITY_API void OutputEntityDescription(FOutputDevice& Ar, const FMassEntityManager& EntityManager, const FMassEntityHandle Entity, const TCHAR* InPrefix = TEXT(""));
217
218 static MASSENTITY_API void SelectEntity(const FMassEntityManager& EntityManager, const FMassEntityHandle EntityHandle);
220
221 static MASSENTITY_API void HighlightEntity(const FMassEntityManager& EntityManager, const FMassEntityHandle EntityHandle);
223
226
230
232
233 static void DebugEvent(const FName EventName, FConstStructView Payload, const EMassDebugMessageSeverity SeverityOverride = EMassDebugMessageSeverity::Default)
234 {
235 OnDebugEvent.Broadcast(EventName, Payload, SeverityOverride);
236 }
237
238 template<typename TMessage, typename... TArgs>
239 static void DebugEvent(TArgs&&... InArgs)
240 {
241 DebugEvent(TMessage::StaticStruct()->GetFName()
243 }
244
251
256 static MASSENTITY_API bool IsEntityManagerInitialized(const FMassEntityManager& EntityManager);
257
266
269
273 static MASSENTITY_API bool DoesArchetypeMatchRequirements(const FMassArchetypeHandle& ArchetypeHandle, const FMassFragmentRequirements& Requirements, FOutputDevice& OutputDevice);
274
279
284
289
294
299
304
309 static MASSENTITY_API bool HasAnyFragmentWriteBreakpoints(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType = nullptr);
310
315
320
325
330
335
340
345
349 static MASSENTITY_API void ClearFragmentWriteBreak(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity);
350
354 static MASSENTITY_API void ClearAllFragmentWriteBreak(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType);
355
359 static MASSENTITY_API void ClearAllEntityBreakpoints(const FMassEntityManager& EntityManager, FMassEntityHandle Entity);
360
366
371
375 static MASSENTITY_API TSharedPtr<FStructOnScope> GetFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity);
376
380 static MASSENTITY_API bool GetFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity, TSharedPtr<FStructOnScope>& OutStructData);
381
385 static MASSENTITY_API const FMassArchetypeSharedFragmentValues& GetSharedFragmentValues(const FMassEntityManager& EntityManager, FMassEntityHandle Entity);
386
390 static MASSENTITY_API TSharedPtr<FStructOnScope> GetSharedFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity);
391
395 static MASSENTITY_API bool GetSharedFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity, TSharedPtr<FStructOnScope>& OutStructData);
396
400 static MASSENTITY_API TSharedPtr<FStructOnScope> GetConstSharedFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity);
401
405 static MASSENTITY_API bool GetConstSharedFragmentData(const FMassEntityManager& EntityManager, const UScriptStruct* FragmentType, FMassEntityHandle Entity, TSharedPtr<FStructOnScope>& OutStructData);
406
411
416
420 static void ShutdownDebugger();
421
422private:
423 // @todo: contain static data in an instanced struct and setup/teardown in startup/shutdown module
428
431};
432
433#else
434
439
441{
442 static FString GetSingleRequirementDescription(const FMassFragmentRequirementDescription&) { return TEXT("[no debug information]"); }
443 static FString GetRequirementsDescription(const FMassFragmentRequirements&) { return TEXT("[no debug information]"); }
444 static FString GetArchetypeRequirementCompatibilityDescription(const FMassFragmentRequirements&, const FMassArchetypeHandle&) { return TEXT("[no debug information]"); }
446};
447
448#define MASS_IF_ENTITY_DEBUGGED(a, b) false
449#define MASS_BREAK_IF_ENTITY_DEBUGGED(a, b)
450#define MASS_BREAK_IF_ENTITY_INDEX(a, b)
451#define MASS_SET_ENTITY_DEBUGGED(a, b)
452
453#endif // WITH_MASSENTITY_DEBUG
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
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
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define DECLARE_TS_MULTICAST_DELEGATE_OneParam(DelegateName, Param1Type)
Definition DelegateCombinations.h:50
#define DECLARE_TS_MULTICAST_DELEGATE_ThreeParams(DelegateName, Param1Type, Param2Type, Param3Type)
Definition DelegateCombinations.h:68
#define DECLARE_TS_MULTICAST_DELEGATE(DelegateName)
Definition DelegateCombinations.h:26
#define DECLARE_TS_MULTICAST_DELEGATE_TwoParams(DelegateName, Param1Type, Param2Type)
Definition DelegateCombinations.h:59
EMassFragmentAccess
Definition MassRequirements.h:18
EMassFragmentPresence
Definition MassRequirements.h:33
T TNotNull
Definition NotNull.h:307
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition IDelegateInstance.h:14
Definition NameTypes.h:617
Definition OutputDevice.h:133
Definition StructOnScope.h:13
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition AndroidPlatformMisc.h:14
Definition UnrealString.h.inl:34
Definition SharedPointer.h:692
Definition SharedPointer.h:153
Definition SharedPointer.h:1295
Definition Mutex.h:18
Definition MassProcessor.h:321
Definition MassProcessor.h:78
Definition Object.h:95
Definition Class.h:1720
Type
Definition TokenizedMessage.h:21
@ Error
Definition TokenizedMessage.h:23
@ Warning
Definition TokenizedMessage.h:25
@ Info
Definition TokenizedMessage.h:26
@ EntityManager
Definition MovieSceneEvaluationCustomVersion.h:21
int
Definition TestServer.py:515
FName GetFName(const UObject *Obj)
Definition ObjectFwd.cpp:13
Definition MassCommandBuffer.h:52
Definition Color.h:486
Definition StructView.h:217
static FConstStructView Make(const T &Struct)
Definition StructView.h:246
Definition MassArchetypeData.h:27
Definition MassEntityTypes.h:74
Definition MassArchetypeData.h:172
Definition MassArchetypeTypes.h:39
Definition MassEntityTypes.h:297
Definition MassDebugger.h:441
static FString GetArchetypeRequirementCompatibilityDescription(const FMassFragmentRequirements &, const FMassArchetypeHandle &)
Definition MassDebugger.h:444
static FString GetRequirementsDescription(const FMassFragmentRequirements &)
Definition MassDebugger.h:443
static FString GetSingleRequirementDescription(const FMassFragmentRequirementDescription &)
Definition MassDebugger.h:442
static FString GetArchetypeRequirementCompatibilityDescription(const FMassFragmentRequirements &, const FMassArchetypeCompositionDescriptor &)
Definition MassDebugger.h:445
Definition MassEntityHandle.h:13
Definition MassEntityManager.h:96
Definition MassEntityQuery.h:51
Definition MassProcessorDependencySolver.h:68
Definition MassRequirements.h:51
Definition MassRequirements.h:160
Definition MassDebugger.h:56
Definition MassDebugger.h:36
int32 EntitiesCountPerChunk
Definition MassDebugger.h:40
SIZE_T WastedEntityMemory
Definition MassDebugger.h:46
SIZE_T BytesPerEntity
Definition MassDebugger.h:48
int32 ChunksCount
Definition MassDebugger.h:42
int32 EntitiesCount
Definition MassDebugger.h:38
SIZE_T AllocatedSize
Definition MassDebugger.h:44
Definition MassDebuggerBreakpoints.h:380
Definition MassDebuggerBreakpoints.h:384