How to use repnotify booleans to drive an animation state machine. ( FULLY NETWORK REPLICATED)

Hi guys so for a long time i have really struggled with the idea of multiplayer replication especially when it comes to animations. I know a lot of people struggle with this issue too so i thought i would share my methods. I had originally set up my animations using Blendspaces as they are simple and easy to use. After a while though i found them to be more limiting and restrictive and so i began experimenting with locomotion state machines. Luckily for me the unreal system isnt that different from the unity system and so i was able to get a decent system up and running with a little trial and error. anyway here ill talk you through it

so first i wanted to know when the player is moving forward/Backward, Left/right or a combination of both. I tried multiple ways to do this using all the different methods suggested on various forum posts such as using the players velocity, direction, axis input etc in the end i went for this setup for ease of use and flexibility.

so what i did was first create action mappings for each movment in the projects input settings like so.

so obviously you can see that when i press W i will be moving forward. S key moving backward, A key moving left and D key moving right. Normal game WASD controls.

then in my character BP i then checked these player inputs to see which one the player was pressing.

I then created a custom event in order to use these inputs as shown here


so for each custom event all i did was give them a name similar to the action inputs. I then made each event set a boolean value that will drive my animation blueprint.


so for each boolean i made them into a repnotify and inside each repnotify function i simply casted to the animation blueprint and set the boolean to be the same as the booleans inside the animation bp.

so here is the repnotify function for moving forward

as you can see whenever the boolean changes, the repnotify function is called and it simply sends the boolean value into the animation blueprint

inside my animation blueprint i simply have the booleans the same as in my character bp i just added ABP suffix on the end so that i can see that these booleans are from the animation blueprint.


And lastly i use these replicated booleans driven by my player input in order to drive my locomotion animation state machine


so for example here is the transition rule for when the player can move from idle into walk forward. as you can see i simply use the replicated boolean . it is really simple .


so the execution goes like this. player presses W on the keyboard >>>>> this calls the server RPC PlayerIsMovingForward custom event (run on server) >>>>>> this sets the boolean playerIsMovingForward inside the character blueprint to be equal to true. >>>>>>this variable is repnotified so it calls the repnotify function>>>>>> inside this function it casts to the animation blueprint and sets the variable playerIsMovingForwardABP to be equal to true>>>> once the boolean is set to true this causes the player to go into the walking forward animation inside the locomotion state.

here is a small video of the final result . first few mins is set as a dedicated server showing two clients. the second half of the video is set to listen server showing server and one client connected.
as you can see the animations still work and are replicated wether it is a dedicated server or not

if anyone wants any help with replication or setting up a system like this drop me a pm and ill try to help when i can

thanks guys

Did you try client side prediction with forcelag with this setup as well? If you just play the anim after the server stent something I would expect some delay. This is not important for all anims (e.g. holster weapon or something like this) but movement should work insta on the client even if this means he causes a state that is not verified yet but later and is in the future gameplay wise. Normal movement like this or crouch is already replicated with the CharacterMovementComponent and is predicted very well. Even crouch got some implemented checks already (like if you would stand up with a client he still keeps the small capsule-size until there is free-space to stand up and predefined walking speed for crouch). While this on-rep or server-event -> multicast-event is a way to trigger custom-anims that are no part of the CharacterMovementComponent I think there must be a good reason to use it like that.

My project is steam enabled . I tested it properly by packaging the project and sending it to a friend we both logged into steam and connected to the game live over the Internet from two different networks

How do I test with forcelag I’ve never done it ?? Thanks

What do you mean by normal movent like this is already replicated with the character movement?

Yes you can use epics already built in replicated functionality for most stuff but it only covers basic movement and not complicsted custom animation/movement like in my project .

The character movement component Is driven/replicated through the players velocity/speed and rotation/direction which is how I originally had my system set up and the results were pretty good but I wasn’t able to get the full range of movement using it . I’ve tried every combination of things I can think of and every forum post suggestion I can find

This is the only solution I have found so far that actually works .

If anyone knows a better way to get the full range of movement and animations synced/replicated then I’m all ears . By full range I mean forwards backwards walking , forwards backwards running, forwards diagonal running, backwards diagonal running, strafe left, strafe right , strafe forwards 45 degree, strafe backwards 135 degree and all transitioning into starts and stops to idle .

I’ve literally tried everything

Make a series of “Excecute Console Command” and enter all of the commands below. Afterwards bind it to some key:

Net PktLoss=1
Net PktOrder=0
Net PktDup=0
Net PktLag=150
Net PktLagVariance=0
p.netshowcorrections 1
log lognetplayermovement verbose

In game start a server and one or two local clients and hit the key with the input action that is executing all these. You would see the difference quickly. Reference: What commands can I use to simulate network conditions? - UE4 AnswerHub

That type of movement is already replicated as it is one of the main important ones. You could just use this info in your anim-BP. The type of replication that you’ve posted is usefull if you have to cover some animations that require some further infos that are not already covered and replicated by the CharacterMovementComponent.

Pretty much every shooter needs the movement (and more) that you’ve described above. :slight_smile:

Just use a 8x8 2D-Blendspace. X-Axis -180/180 Direction. Y-Axis - 0/max-run-speed.
Top-row left to right (used all 8):
RunBackwards - StrafeRun135Left - StrafeRunLeft - StrafeRun45Left - RunForwards - StrafeRun45Right - StrafeRunRight - StrafeRun135Right - RunBackwards

Mid-row left to right (used all 8):
WalkBackwards- StrafeWalk135Left - StrafeWalkLeft - StrafeWalk45Left - WalkFowards - StrafeWalk45Right - StrafeWalkRight - StrafeWalk135Right - WalkBackwards

Bottom-row (used 3: outer-left, mid, outer-right):
Idle - - - - Idle - - - - Idle

You could place the Mid-row in the mid of your blend-space or one or two rows below (depends on how much you would differ run-speed from walk-speed). You could get your speed from the character-BP via “GetVelocity->Vectorlength” as float and Direction as well from the character-BP via “GetActorRotation->CalculateDirection” where the Velocity input is yet again the same “GetVelocity” from the character-BP without to think about replication just in your Event-Graph of your anim-BP. You could use the 2D-Blendspace (or a simpler one) for crouch as well and blend between them in your state-machine (instead of blend from each direction in the state-machine from crouch to uncrouch).

thanks for telling me how to do the lag simulation. and as for youre other suggestion that is exactly how i originally had it set up and like i said it worked perfectly but i wasnt able to get the full range of movments by that i meant adaptive start and stops as shown in my first video so that when the player lets go of the key it plays a stopping animation first before going into idle. no matter what i tried i just couldnt get it to work using blendspaces and the above method. thats why i began experimenting with state machines

Probably the adaptive stop/start gives enough delay so possible lag does not matter that much. If not then I think I would try some ifs from speed and direction just pulled in the anim-bp from the character-bp. Like “if prev_speed == 0 and current_speed > 0 trigger_adaptive_start” and “if prev_speed > 0 and current_speed < lower_than_walkspeed trigger_adaptive_stop” and the direction just from the direction and checked against isfalling.

yeah the trouble with that is the direction variable is unrealiable as it fluctuates . there is a problem with the calculate direction node that unreal has built in and all the forum post fixes ive tried havnt worked and im too much of a noob to figure out how to calculate the direction myself . and it still doesnt change the fact i cant use the blendspace as because it is driven by speed you have to have an idle animation at speed 0 so no way to put starts and stops into the blendspace and also i have 6 different strafe anims plus 2 more start and stops for strafes so it really is impossible to do all that with blendspaces .