![]() |
UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
|
#include <MassEntityBuilder.h>
Inheritance diagram for UE::Mass::FEntityBuilder:Classes | |
| struct | FPendingRelationParams |
| struct | FStructInstanceFindingPredicate |
Static Public Member Functions | |
| static UE_API FEntityBuilder | Make (const TSharedRef< FMassEntityManager > &InEntityManager, const FMassArchetypeCompositionDescriptor &Composition, TConstArrayView< FInstancedStruct > InitialFragmentValues={}, TConstArrayView< FConstSharedStruct > ConstSharedFragments={}, TConstArrayView< FSharedStruct > SharedFragments={}) |
| static UE_API FEntityBuilder | Make (const TSharedRef< FMassEntityManager > &InEntityManager, const FMassArchetypeCompositionDescriptor &Composition, TArray< FInstancedStruct > &&InitialFragmentValues, TArray< FConstSharedStruct > &&ConstSharedFragments, TArray< FSharedStruct > &&SharedFragments) |
Protected Member Functions | |
| UE_API void | CacheSharedFragmentValue () |
| UE_API void | CacheArchetypeHandle () |
| UE_API void | InvalidateCachedData () |
FEntityBuilder is a utility struct that provides a convenient way to create and configure entities in the Mass framework. It bridges multiple APIs from FMassEntityManager, MassSpawnerSubsystem, MassEntityTemplates, and other related components, allowing for streamlined entity creation and configuration.
Key Features:
Example Usage: { FEntityBuilder Builder(EntityManager); Builder.Add<FTransformFragment>(FTransform(FVector(100, 200, 300))) .Commit(); // the entity gets reserved and built by this call }
{ FEntityBuilder Builder(EntityManager); FMassEntityHandle ReservedEntity = Builder; // Entity handle reserved, can be used for commands. Builder.Add_GetRef<FTransformFragment>().GetMutableTransform().SetTranslation(FVector(100, 200, 300)); Builder.Commit(); // Entity creation is finalized at this point. }
// Example of chaining with FMassEntityManager's MakeEntityBuilder() method: FMassEntityHandle NewEntity = EntityManager.MakeEntityBuilder() .Add<FMassStaticRepresentationTag>() .Add<FTransformFragment>() .Add<FAgentRadiusFragment>(FAgentRadiusFragment{ .Radius = 35.f}) .Add<FMassVelocityFragment>() .Commit();
Current Limitations:
|
explicit |
Constructs a FEntityBuilder using a reference to a FMassEntityManager.
|
explicit |
Constructs a FEntityBuilder using a shared reference to a FMassEntityManager.
| UE::Mass::FEntityBuilder::FEntityBuilder | ( | const FEntityBuilder & | Other | ) |
Copy constructor - copies-create a new instance that represents a new entity and does not carry over reserved handle.
| UE::Mass::FEntityBuilder::~FEntityBuilder | ( | ) |
Destructor - automatically commits entity creation if not explicitly aborted or committed beforehand.
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | ) |
Adds a tag of type T to the entity.
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | ) |
Adds a chunk fragment of type T to the entity.
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | const FInstancedStruct & | ElementInstance | ) |
Adds a fragment instance to the Entity Builder, treating the contents according to its type
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | FInstancedStruct && | ElementInstance | ) |
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | TArgs &&... | InArgs | ) |
Adds a fragment of type T to the entity, constructing it with the provided arguments.
| FEntityBuilder & UE::Mass::FEntityBuilder::Add | ( | TNotNull< const UScriptStruct * > | ElementType | ) |
Adds the ElementType to the target archetype's composition
| T & UE::Mass::FEntityBuilder::Add_GetRef | ( | TArgs &&... | InArgs | ) |
Adds a fragment of type T to the entity and returns a reference to it, constructing it with the provided arguments. The function will assert if an element of type T already exists.
| T | - The type of fragment to add. |
| InArgs | - Constructor arguments for initializing the fragment. |
| FEntityBuilder & UE::Mass::FEntityBuilder::AddRelation | ( | FMassEntityHandle | OtherEntity, |
| Relations::ERelationRole | InputEntityRole = Relations::ERelationRole::Object |
||
| ) |
templated helper function for calling the other AddRelation function
| FEntityBuilder & UE::Mass::FEntityBuilder::AddRelation | ( | UE::Mass::FTypeHandle | RelationTypeHandle, |
| FMassEntityHandle | OtherEntity, | ||
| Relations::ERelationRole | InputEntityRole = Relations::ERelationRole::Object |
||
| ) |
Adds information about a specific relation instance to be added once the entity gets created. The function will simply store the information without any checks for validity or duplication. If you want to override existing relation data call ForEachRelation.
| bool UE::Mass::FEntityBuilder::AppendDataFromEntity | ( | const FMassEntityHandle | SourceEntityHandle | ) |
Appends all element types and values stored by the entity indicated by SourceEntityHandle.
| SourceEntityHandle | valid handle for a fully constructed, built entity. |
|
protected |
|
protected |
| FMassEntityHandle UE::Mass::FEntityBuilder::Commit | ( | ) |
Finalizes the creation of the entity with the specified fragments and configurations. Note that this function needs to be called manually, no automated entity creation will take place upon builder's destruction.
| FMassEntityHandle UE::Mass::FEntityBuilder::CommitAndReprepare | ( | ) |
A wrapper for "Commit" call that, once that's done, prepares the builder for another commit, forgetting the handle for the entity just created, and reverting the state back to "ReadyToCommit"
|
inline |
Advanced functionality. Can be used to provide additional parameters that will be used to create the entity's target archetype. Note that these parameters will take effect only if the target archetype doesn't exist yet.
| bool UE::Mass::FEntityBuilder::CopyDataFromEntity | ( | const FMassEntityHandle | SourceEntityHandle | ) |
Copies all element types and values stored by the entity indicated by SourceEntityHandle. Any existing builder data will be overridden
| SourceEntityHandle | valid handle for a fully constructed, built entity. |
| T * UE::Mass::FEntityBuilder::Find | ( | ) |
Finds and retrieves a pointer to a fragment of type T if it exists.
| T | - The type of fragment to find. |
| void UE::Mass::FEntityBuilder::ForEachRelation | ( | const TFunctionRef< bool(FPendingRelationParams &)> & | Operator | ) |
Calls the provided Operator function for every stored pending relation data instance. The return value of the Operator is used to determine whether the relation data instance should be kept (meaning: return false for each element you want to remove). The potential element removal is stable.
| FMassArchetypeHandle UE::Mass::FEntityBuilder::GetArchetypeHandle | ( | ) |
| FMassEntityHandle UE::Mass::FEntityBuilder::GetEntityHandle | ( | ) | const |
Converts the builder to a FMassEntityHandle, reserving the entity handle if not already committed.
|
inline |
| T & UE::Mass::FEntityBuilder::GetOrCreate | ( | TArgs &&... | InArgs | ) |
Adds a fragment of type T to the entity and returns a reference to it, constructing it with the provided arguments. If a fragment of the given type already exists then it will be overriden and its reference returned.
|
inline |
|
protected |
|
inline |
|
inline |
Checks whether the builder is in a valid, expected state
|
static |
Creates an instance of FEntityBuilder and populates it with provided data, using move-semantics on said data
|
static |
Creates an instance of FEntityBuilder and populates it with provided data
| FEntityBuilder & UE::Mass::FEntityBuilder::operator= | ( | const FEntityBuilder & | Other | ) |
Assignment operator - copies represent new entities, with no carryover of reserved handle from the original.
| FEntityBuilder & UE::Mass::FEntityBuilder::operator= | ( | FEntityBuilder && | Other | ) |
Move assignment operator - moves over all the data from Other, including the internal state (like whether the entity handle has already been reserved)
| void UE::Mass::FEntityBuilder::Reprepare | ( | ) |
if the builder is in "Committed" state it will roll back to ReadyToSubmit and reset the stored entity handle
Resets the builder to its initial state, discarding all previous entity configurations.
| bReleaseEntityHandleIfReserved | configures what to do with the reserved entity handle, if it's valid. |
| bool UE::Mass::FEntityBuilder::SetReservedEntityHandle | ( | const FMassEntityHandle | ReservedEntityHandle | ) |
Stores ReservedEntityHandle as the cached EntityHandle. The ReservedEntityHandle is expected to be valid and represent a reserved entity. These expectations will be checked via ensures. If the existing EntityHandle also represents a valid, reserved entity, that handle will be released.