Hi everyone,
I have been testing the Mass Entity system in UE5.4 recently, I plan to spawn many enemies and they are chasing the player.
I write my trait and processor in CPP, and my custom subsystem to get and pass the player location to all the processors, plus with some traits comes with UE like Avoidance, Steering, Movement. When I use DebugVisualization with static mesh, everything works fine. Here is a video showcase that:
Then I switch to Mass Movable Visualization Trait (Since UE5.4 said the Visualization Trait is soft deprecated, and recommend using Mass Movable Visualization Trait or Mass Stationary Visualization Trait ). I use 2 actor based on Character class, for high-res and low-res actor, then with a static mesh, here is the setup:
Then the result look like this, the high-res low-res actors were not moving, only the static meshs are moving, and when I enable the debug mode, I can see the entities are moving, just the visualization actor are not following the data, here is a video showing that:
My Entity Config Asset looks like this, the Advance Movement Trait is the one I made myself, others are from UE tools:
The Execute function in my processor looks like this, I modify the FMassMoveTargetFragment data to move the entities:
void UAdvanceMovementProcessor::Execute(FMassEntityManager& EntityManager, FMassExecutionContext& Context)
{
EntityQuery.ForEachEntityChunk(EntityManager, Context, ([this](FMassExecutionContext& Context)
{
FFollowPlayerShareFragment& FollowPlayerSharedFragment = Context.GetMutableSharedFragment<FFollowPlayerShareFragment>();
UWorld* World = Context.GetWorld();
float DeltaTime = Context.GetDeltaTimeSeconds();
UMyWorldSubsystem* MySubsystem = nullptr;
if (World)
{
MySubsystem = World->GetSubsystem<UMyWorldSubsystem>();
FollowPlayerSharedFragment.PlayerLocation = MySubsystem->GetPlayerLocation();
}
//const FVector& PlayerLocation = FollowPlayerSharedFragment.PlayerLocation;
const TArrayView<FTransformFragment> TransformsList = Context.GetMutableFragmentView<FTransformFragment>();
const TArrayView<FMassMoveTargetFragment> NavTargetsList = Context.GetMutableFragmentView<FMassMoveTargetFragment>();
const FMassMovementParameters& MovementParams = Context.GetConstSharedFragment<FMassMovementParameters>();
for (int32 EntityIndex = 0; EntityIndex < Context.GetNumEntities(); ++EntityIndex)
{
FTransform& Transform = TransformsList[EntityIndex].GetMutableTransform();
FMassMoveTargetFragment& MoveTarget = NavTargetsList[EntityIndex];
FVector CurrentLocation = Transform.GetLocation();
if (MySubsystem)
{
MoveTarget.Center = FVector(MySubsystem->GetPlayerLocation().X, MySubsystem->GetPlayerLocation().Y, 0.f);
}
FVector TargetVector = MoveTarget.Center - CurrentLocation;
TargetVector.Z = 0.f;
MoveTarget.DistanceToGoal = TargetVector.Size();
MoveTarget.Forward = TargetVector.GetSafeNormal();
Transform.SetScale3D(FVector(1.f));
}
})
);
}
My guess is either I am missing some traits or fragments or maybe I need to do some setup on the high-res low-res actor bp?
I would greatly appreciate any ideas or guidance you can provide. Thank you for your time and support!