FMassActorFragment in Mass Framework

What's purpose of FMassActorFragment and how to use that in Mass Framework? Mass Framework is a ECS for managing crowds and traffic in Unreal 5.0 and above.

FMassActorFragment MassGameplay built-in resource

FMassActorFragment allows to access Mass controlled Actors from the Mass system. It may be used to trigger any function, push any values and so on, see the example below.

Adding FMassActorFragment to MassConfiguration

FMassActorFragment can be placed into the process either manually through the Assorted Fragments section of Mass Entity Config Asset, or with the help of code BuildContext.AddFragment<FMassActorFragment>(); placed in a Trait, see both methods at the Mass page.

Once FMassActorFragment is placed in the system, you can use it to access Mass Actors as follow:

void USampleProcessor::ConfigureQueries(){
	EntityQuery.AddRequirement<FMassActorFragment>(EMassFragmentAccess::ReadWrite);
}
void USampleProcessor::Execute(FMassEntityManager& EntityManager, FMassExecutionContext& Context)
{
	EntityQuery.ForEachEntityChunk(EntityManager, Context, [this](FMassExecutionContext& Context)
	{
		TArrayView<FMassActorFragment> ActorFragments = Context.GetMutableFragmentView<FMassActorFragment>();
		const int32 NumEntities = Context.GetNumEntities();
		for (int32 EntityIdx = 0; EntityIdx < NumEntities; EntityIdx++)
		{
			FMassActorFragment& ActorFragment = ActorFragments[EntityIdx];
			AActor* Actor = ActorFragment.GetOwnedByMassMutable();
			if(Actor){
				ASampleCharacter* Character = Cast<ASampleCharacter>(Actor);
				Character->DoAnything();	
			}
		}
	}
}

Note: There are many other ways of using FMassActorFragment to do the same.