Download

Trouble with replicating an animation

Ok, so I wasn’t able to see the attack animation of my characters across the network in my multiplayer game. Easy, I thought, I just need to make sure the variable which controls whether or not an attack is valid is replicated. Well, it half fixed the problem. The client can see when the server is attacking, but the server can’t see when the client attacks.

I had thought that if I set a variable to replicate then it would replicate from client to server and from server to client. Is that not the case? Do I need to do something additional to replicate client actions to the server?

Cheers

I have this exact same problem atm, all clients can see the animation fireing.
But its never played server side.

I have a extended animation instance class that have replicated variabels that is set on the server when player presses attack.

Hey guys! With replication, variables are only replicated one-way, from server to client. You need to call a replicated function (RPC) to the Server itself from the client if the client would like to change the animation state(The server can then validate that this is a valid animation for the the client to play). The server then can change the value of the replicate variable on the server-side which will then be replicated back to the clients and the animation should work both client-side and server-side.

Hope this helps and let me know if you have any more questions or need some sample code!

-Connor

Actualy if you have a sample code that be realy great.
As i think my logic is wrong.
Thanks!

Thankyou CBrew! I suspected this might be the case. I will implement it as you suggest and see how it goes.
Cheers,
Ben

As WCode asked, I can provide some examples to point you in the right direction(note that this code is “free-handed” and haven’t tried to compile it, but you should be able to get the idea)

First off lets define our replicated variable and function that will be called on the client and be replicated to the server. Put this in the header file where applicable.



/** If this is true, the character should use the dance animation */
UPROPERTY(Replicated)
bShouldDance;

/** Called on a client to tell the server to start the dance animation */
UFUNCTION(Server, WithValidation)
void SERVER_StartDanceAnimation();


Now in the .cpp file we will implement the replicated function



#include "UnrealNetwork.h"

void ADancingCharacter::GetLifetimeReplicatedProps(TArray< FLifetimeProperty > & OutLifetimeProps) const
{
	Super::GetLifetimeReplicatedProps(OutLifetimeProps);
	//Make sure to set up the bool for replication
	DOREPLIFETIME(ADancingCharacter, bShouldDance);
}


bool ADancingCharacter::SERVER_StartDanceAnimation_Validate()
{
	//Check to make sure that it is not illegal for the character to be dancing right now or something (cheat prevention)
	//For now we will just return true because this is an example, and you may or may not need true validation depending on what you are doing
	return true;
}

void ADancingCharacter::SERVER_StartDanceAnimation_Implementation()
{
	bShouldDance = true;
}


Hope this helps! Let me know if you have any questions or if this doesn’t work for some reason. If needed I can help you out more in depth via Skype!

-Connor

Hello and thanks Connor that is how i am doing it more or less.
I just figuerd out the solution for my problem and it was due to a setting on the skeletal mesh component.
Located in the character class under the Defaults tab of the Player Blueprint. (I have not had time to find its code ecvivelant yet.)

This way when the animation was played the server notice the item the character was holding.
Thanks for the help guys.
Cheers!