UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MassRelationCommands.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "MassCommands.h"
6#include "MassEntityManager.h"
7
8#if CSV_PROFILER_STATS || WITH_MASSENTITY_DEBUG
9# define DEBUG_NAME(Name) , FName(TEXT(Name))
10# define DEBUG_NAME_PARAM(Name) , const FName InDebugName = TEXT(Name)
11# define FORWARD_DEBUG_NAME_PARAM , InDebugName
12#else
13# define DEBUG_NAME(Name)
14# define DEBUG_NAME_PARAM(Name)
15# define FORWARD_DEBUG_NAME_PARAM
16#endif // CSV_PROFILER_STATS || WITH_MASSENTITY_DEBUG
17
18template<typename TRelation>
20{
22
26
27 void Add(const FMassEntityHandle ChildEntity, const FMassEntityHandle ParentEntity)
28 {
30 Parents.Add(ParentEntity);
31 }
32
34 {
35 ensure(ChildEntities.Num() != 0 && ParentEntities.Num() != 0);
36
38
39 if (ChildEntities.Num() > ParentEntities.Num())
40 {
41 // @todo to be improved - we should have a dedicated path for Multi-children -> Single parent operations
42 do
43 {
45 } while (Parents.Num() < TargetEntities.Num());
47 }
48 else
49 {
50 Parents.Append(ParentEntities.GetData(), FMath::Min(ParentEntities.Num(), ChildEntities.Num()));
51 }
52 }
53
54protected:
55 virtual void Reset() override
56 {
57 Parents.Reset();
59 }
60
61 virtual SIZE_T GetAllocatedSize() const override
62 {
64 }
65
66 virtual void Run(FMassEntityManager& EntityManager) override
67 {
69 EntityManager.BatchCreateRelations<TRelation>(TargetEntities, Parents);
70 }
71
73};
74
75#undef DEBUG_NAME
76#undef DEBUG_NAME_PARAM
77#undef FORWARD_DEBUG_NAME_PARAM
#define ensure( InExpression)
Definition AssertionMacros.h:464
FPlatformTypes::SIZE_T SIZE_T
An unsigned integer the same size as a pointer, the same as UPTRINT.
Definition Platform.h:1150
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
#define TRACE_CPUPROFILER_EVENT_SCOPE(Name)
Definition CpuProfilerTrace.h:528
EMassCommandOperationType
Definition MassCommands.h:21
#define FORWARD_DEBUG_NAME_PARAM
Definition MassRelationCommands.h:15
#define DEBUG_NAME_PARAM(Name)
Definition MassRelationCommands.h:14
Definition Array.h:670
UE_REWRITE SizeType Num() const
Definition Array.h:1144
void Reset(SizeType NewSize=0)
Definition Array.h:2246
void SetNum(SizeType NewNum, EAllowShrinking AllowShrinking=UE::Core::Private::AllowShrinkingByDefault< AllocatorType >())
Definition Array.h:2308
UE_NODEBUG UE_FORCEINLINE_HINT SizeType Add(ElementType &&Item)
Definition Array.h:2696
void Append(const TArray< OtherElementType, OtherAllocatorType > &Source)
Definition Array.h:2412
UE_NODEBUG UE_FORCEINLINE_HINT SIZE_T GetAllocatedSize(void) const
Definition Array.h:1059
EMassCommandOperationType OperationType
Definition MassCommands.h:148
Definition MassCommands.h:159
FMassBatchedEntityCommand()=default
TArray< FMassEntityHandle > TargetEntities
Definition MassCommands.h:205
void Add(FMassEntityHandle Entity)
Definition MassCommands.h:167
virtual void Reset() override
Definition MassCommands.h:194
virtual SIZE_T GetAllocatedSize() const
Definition MassCommands.h:189
Definition MassRelationCommands.h:20
void Add(const FMassEntityHandle ChildEntity, const FMassEntityHandle ParentEntity)
Definition MassRelationCommands.h:27
virtual SIZE_T GetAllocatedSize() const override
Definition MassRelationCommands.h:61
FMassCommandMakeRelation(EMassCommandOperationType OperationType=EMassCommandOperationType::Add DEBUG_NAME_PARAM("MakeRelation"))
Definition MassRelationCommands.h:23
void Add(TConstArrayView< FMassEntityHandle > ChildEntities, TConstArrayView< FMassEntityHandle > ParentEntities)
Definition MassRelationCommands.h:33
TArray< FMassEntityHandle > Parents
Definition MassRelationCommands.h:72
virtual void Reset() override
Definition MassRelationCommands.h:55
virtual void Run(FMassEntityManager &EntityManager) override
Definition MassRelationCommands.h:66
Definition MassEntityHandle.h:13
Definition MassEntityManager.h:96