Mover and Mass velocity update

I’m using Mover with MassAI and I’m not sure what’s the best way to pass the velocity when MassAI is changing visualisation to be an Actor based.

In CitySample CitySampleCrowdCharacter::OnGetOrSpawn - which is using CMC it’s just passing the velocity from the fragment to the CMC directly - which can not be done in Mover.

But still I would like to have starting velocity from the Mass Velocity - currently (5.7) it’s starting from 0 to the desired velocity which is passed by the Mover Translator - this is causing the Actor to stop on spawn and continue moving using acceleration and desired velocity.

What would be the best way to pass the velocity from Mass to the Mover when the Actor spawns so it won’t start from 0?

Hey there,

We haven’t done this workflow in particular and don’t have an official way to handle this yet, but you try overriding UMoverComponent::CreateDefaultInputAndState to grab the velocity from the agent and then push that into the initial velocity.

Dustin

Thanks for trying to help but overriding won’t work:

  • CreateDefaultInputAndState is called on PostActorConstruction and InitializeComponents which MassAgentComponent also use to initialize. Will end up with EnityPendingCreation - so no valid entity ID at this point.
  • Also I can not use MassActorSpawnerSubsystem SpawnActor function because of the same reason.

It would be great if you guys can invest some time into Mover and MassAI - for example try to replace CMC in the City Sample with Mover - this way you will get all of the issues I’m getting.

Basically UMassAgentComponent::SetEntityHandleInternal - this is setting the CMC velocity because MassAI can also be replicated. And I need replication also.

That’s why I’m running into a wall and even if I put the velocity on the component initialization (where the Mover default state is created) it won’t be valid in mutliplayer.

Understood. Again, we haven’t fully explored this.

It would be great if you guys can invest some time into Mover and MassAI

We do have plans to show examples of this work in the future.

One thing you can also try is to expose the BackendLiasonComponent on Mover (either through functions or directly) the use ReadPendingSyncState and WritePendingSyncState to write your data.

Here’s an example:

//Setter function
void UNavMoverComponent::SetVelocityExternal(const FVector& DesiredVelocity, bool bRunPhysicsNoController)
{
	UE_LOG(LogMover, VeryVerbose, TEXT("Setting %s Velocity to %s from external source"), *GetNameSafe(GetOwner()), *DesiredVelocity.ToString());
	bRequestedNavMovement = true;
	if (MoverComponent.IsValid())
	{
		if (USceneComponent* UpdatedComponent = MoverComponent->GetUpdatedComponent())
		{
			UpdatedComponent->ComponentVelocity = DesiredVelocity;
		}
 
		if (bMoverHasAuthority)
		{
			WriteUpdatedComponentToSyncState();
		}
	}
	bRunAgentWithNoController = bRunPhysicsNoController;
}
 
//Using the BackendLiason
void UNavMoverComponent::WriteUpdatedComponentToSyncState()
{
	IMoverBackendLiaisonInterface* LiaisonComponent = GetOwner()->FindComponentByInterface<IMoverBackendLiaisonInterface>();
	if (!ensure(LiaisonComponent != nullptr))
	{
		return;
	}
	
	if (MoverComponent.IsValid())
	{
		USceneComponent* UpdatedComponent = MoverComponent->GetUpdatedComponent();
		
		// Read, edit, write out the sync state based on the move results
		FMoverSyncState PendingSyncState;
		if (UpdatedComponent && LiaisonComponent->ReadPendingSyncState(OUT PendingSyncState))
		{
			if (FMoverDefaultSyncState* DefaultSyncState = PendingSyncState.SyncStateCollection.FindMutableDataByType<FMoverDefaultSyncState>())
			{
				DefaultSyncState->SetTransforms_WorldSpace(
					UpdatedComponent->GetComponentLocation(),
					UpdatedComponent->GetComponentRotation(),
					UpdatedComponent->ComponentVelocity,
					DefaultSyncState->GetMovementBase(),
					DefaultSyncState->GetMovementBaseBoneName()
				);
				LiaisonComponent->WritePendingSyncState(PendingSyncState);
			}
		}
	}
}

This may not be a 1-1 of what you need, but it does show how you could inject stuff to mover from an external source.

Dustin