Replicate animation

I believe have some basic misunderstanding of how replication works.

I’m trying to add the death animation to a character, which works on the server, but not on the clients. I’ve read I have to set a replicated variable which will indirectly trigger the animation. But I can’t get it to work, the animation is not played on the clients.

To simplify I’ve taken the TopDown sample to make a MWE of the problem. I’ll add screenshots but I can also upload the project if necessary.

So what I’ve done is set a replicated boolean testvar on the TopDownCharacter blueprint. On the ThirdPerson_AnimBP I’ve added a variable boolean dieffsAnim and in its Animation Graph I’ve added a state DIEffs, reached or leaved depending on dieffsAnim value.

On the event graph of ThirdPerson_AnimBP this variable is updated on Event Blueprint Update Animation by casting Try Get Pawn Owner to TopDownCharacter and fetching dieffs and assigning it to dieffsAnim.

I’ve tried replicating dieffsAnim as well, but I guess it shouldn’t be necessary.

I suspect the problem lies on the pawn not being owned by the client, but I’m not sure how to handle that.

The pawn dies when I press Q. On the original project the damage is applied using ApplyDamage, which runs on the server only. Dying has to be on the server as authority, but I feel that I first I need to understand this so I can continue learning.

As you can see, I also change the name of the character pressing M and N, the name being replicated. Each game window prints, say, for two clients on standalone:

LogBlueprintUserMessages: [TopDownCharacter_C_0] Server: falseNone
LogBlueprintUserMessages: [TopDownCharacter_C_1] Server: falseNone
LogBlueprintUserMessages: [TopDownCharacter_C_1] Client 1: falseNone
LogBlueprintUserMessages: [TopDownCharacter_C_0] Client 1: falseMr. M: 
LogBlueprintUserMessages: [TopDownCharacter_C_1] Client 2: falseNone
LogBlueprintUserMessages: [TopDownCharacter_C_0] Client 2: falseNone

Shouldn’t all say that one of the characters is called Mr. M?

I’ve figured it out. I had indeed a basic misunderstanding.

When a variable is replicated, it’s replicated from the server to the clients. Which means that the client does not replicate it to anybody.

Both dieFFS and playername were changed on the client, and therefore not replicated. To achieve this you have to create a custom event, say change name, ran only on the server with the name as a parameter. This event is triggered by the client and then processed on the server. If you set the playername variable as replicated it will now be sent back to the clients since it’s the server changing it.

In addition to that, I had forgotten to assign the new Animation blueprint to the TopDownCharacter which is why it wasn’t triggering the dying animation, since the ApplyDamage was correctly computed on the server and its replication was actually working.