Set animation blueprint variables from chracter blueprint in a networked game?

Hello, I am working on a networked game with Unreal Engine 5.3 and I’m encountering a variety of issues when attempting to set variables in the animation blueprint from the character blueprint.

This is the approach I am doing:

In begin play:

  1. First I get my skeletal mesh
  2. Get anim instance
  3. Cast to animation blueprint
  4. As animation blueprint set as variable


Ignore the node connections being strange, this is because I moved the nodes just to get them in frame.

Then when I want to set a variable in the animation blueprint:

  1. Get variable reference to the animation blueprint
  2. Set variable

This works, but only for the client, which is a problem since this is a networked game.
However, I can’t find a safe way to replicate setting variables… Here are things I have tried:

  • Setting the variable in the server (SV) and/or multicast (SVP): Returns an error saying the animation blueprint variable is “none”
  • Setting the variables involved as replicated / repnotify: Does nothing at all
  • Setting the reference to the ABP in server (or server + multicast, or server + replicated variable) and then performing the variable updates in a similar manner: This returns no errors, but also does nothing whatsoever.


image
(As noted before, attempting to set the “crouching” variable in the SV or SVP custom events returns an error)

Originally, I had a rather standard set-up where the animation blueprint fetched the variables from the character. Essentially, just looking up the value of the corresponding variables in the character blueprint each animation update to then copy them to a duplicate variable in animation blueprint (for example: look up the value of “crouch command” and then set “crouching” to that).
This is, of course, a terrible approach, not only wasting processing power by checking a value each frame instead of only setting variables when something happens, but requiring a lot of additional calculations for more complicated things, and duplicate variables in the character for the animation blueprint to copy from.

Oddly enough, when the animation blueprint was just copying the character blueprint, it was all running on the client too, I never did anything special to make it replicate over the network, therefore I had assumed that just updating a variable (even if from another blueprint) would be replicated without an issue.

I’d greatly appreciate any advice. I’ve looked at countless tutorials and forum posts and was unable to find an answer.

I am beginning to believe that I’ve misunderstood how animation blueprints work in the context of networking, and that somehow my prototype has been working flawlessly up until now entirely through cosmic coincidence.

Unfortunately, I’m still not entirely sure how to approach a solution. Most workflows I have found online either rely on my prior method of checking for variable changes every update, or using RPC functions, creating a function for each variable that exists entirely to update that variable, which seems like a lot of boilerplate to maintain.

I am certain that a modern and elegant engine like Unreal must have a better solution, there has to be a way to set variables over a network that does not require boilerplate, but I’m struggling to find it. It is out there…

The values of the variables should typically be determined on the server. Then you should make the server broadcast values to the clients (perhaps through OnRep) and make clients stuff the variable values into the animation blueprint.
However, if the values are entirely cosmetic/client-side (“foot IK” type stuff), then you can have each client determine the appropriate value of those variables. It should Just Work in those cases, as the same pawn is replicated to each client. (But the PlayerController is not.)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.