ECS Mass, Trait purpose and instantiating entity

Korred
Wed, 08 May 2024 13:07:35 +0000
C++

Hi
Currently I am trying to learn Mass system, I understand concepts like Fragment, Tag, Processor, Subsystem, but I am having truble understanding what purpose has Trait. Is some way to encapsulete multiple fragments and tag?
Given code below Trait just encapsulates Fragments and Tag.

void UMoverMassTrait::BuildTemplate(FMassEntityTemplateBuildContext& BuildContext, const UWorld& World) const
{
	BuildContext.RequireFragment<FTransformFragment>();
	BuildContext.RequireFragment<FMassVelocityFragment>();
	BuildContext.AddFragment_GetRef<FMassForceFragment>().Value = StartingForce;

	BuildContext.AddTag<FMSBasicMovement>();

}

I can create manualy Entety by this simple code

		FMassEntityHandle ReserverdEntity = EntityManager->ReserveEntity();
		FLocationFragment location;
		location.position = FVector(Index * 100, 0, 120);
		location.rotation = FVector::ZeroVector;
		EntityManager->Defer().PushCommand<FMassCommandBuildEntity>(ReserverdEntity, location);

In this given example I define entety that has only FLocationFragment and then create it, but what i can do is in simillar fashon add moree Fragments and Tags to given entity.
Can I do simillar thing with traits?
like

UMoverMassTrait.FTransformFragment = FVector();
UMoverMassTrait.FMassVelocityFragment = FVEctor();
EntityManager->Defer().PushCommand<FMassCommandBuildEntity>(ReserverdEntity, UMoverMassTrait);

2 posts - 2 participants