Hello,
I have a multiplayer over network game.
I have an actor which has simulated physics.
When a pawn overlaps with this actor, I want to attach the RootComponent of this actor to a socket of the pawn.
On the server, when the overlap event occurs, I disable the physics simulation and do the attachment of the actor, and set a state in the grabbed actor. This state is replicated over network. I marked this state in the actor as replicated using a function
UPROPERTY( Transient, ReplicatedUsing=OnRep_State )
TEnumAsByte< EBallState::Type > State;
In OnRep_State:
void OnRep_State()
{
UpdatePhysicsForState(); // Here, I disable the physics
}
The problem I have is that the attachment of the actor on another actor is also replicated, using the function OnRep_AttachmentReplication. And as I don’t control the order in which the repnotifies are called, I end up with the OnRep_AttachmentReplication being called BEFORE the OnRep_State function, and on the client, the attachment fails because the physics simulation has not been disabled yet.
The solution I put in place is to attach the actor to the parent actor on the client in the OnRep_State:
void OnRep_State()
{
UpdatePhysicsForState(); // Here, I disable the physics
if ( State == Grabbed )
{
check( CharacterOwner != NULL );
AttachRootComponentTo( CharacterOwner->Mesh, LOCAL_RightHandSocketName, EAttachLocation::SnapToTarget );
}
}
This works well, but it would be easier to understand if I did not have this check, by being able to control the order of the calls to the rep notifies.
Is it possible?
Is there a more general solution I’m not seeing there?
Thanks