Animation replication is not working
Hi I am making a game based off of the multiplayer ue4 youtube tutorial series, My character animations are not replicating correctly i have tried many of the methods on youtube and based on my own understanding tried some things, nothing has worked. Screen shot 6 shows the replication script as well as the settings for my character's replication, Screen shot 7 shows the event graph of my anim blueprint screenshot 8 shows the condition for the animation to be played. I would love if someone could look through the code and help me find this issue.
asked Mar 25 '19 at 06:24 PM in Blueprint Scripting
First off, some general points you should keep in mind:
-If you want the clients to see what the server is doing, the appropriate variables need to be replicated (variables ONLY replicate from Server to Client, not the other way around). One way to do this is what you are trying to do, which is to use a replicated variable that is called on tick from the Anim BP. What you are missing is that you need to set that variable on the server if the clients are calling the code. In other words, the server should simply set the "Dashing" bool, but the clients should run a custom event running on the server, which in turns run a multicast event, which then sets the "Dashing" bool. Alternatively, you can try the method I'm suggesting below using interface calls if you don't need it set on tick.
-If you want the server to see what clients are doing, they need to run the code you want replicated on the server.
-If you want clients to see what other clients are doing, you need to get that code to run on all the connected clients (this is what a multicast would accomplish).
So for example, if all you're needing to do is replicate an animation that's triggered in your Anim BP by a boolean, and you don't need that boolean checked on tick, you could try the following:
I've attached screenshots of a working example I'm using in my own project below, where I'm setting an "Is Taking Cover" variable in my Anim BP so the taking cover animation is replicated to everyone. If you're not interested in this approach, like I said in the first paragraph, it's very simple to just replicate the variable and set it in your Anim BP tick event. Just make sure clients are setting that variable on the server.
Interface call in Anim BP:
Custom Events in Player Character:
Switch Has Authority check:
answered Mar 27 '19 at 05:56 AM
It looks like you flipped the names on your RPCs, and while that's confusing, it isn't what's breaking your code.
"Switch has Authority" is a node that checks to see if the object running the code is on the server or on the client. In most multiplayer games, the server must have authority to prevent cheating. What that means is that the game code should run on the server and the client should have no say whether the code works or not. All the client does is sends requests to the server, then the server says "hey, can he do that or is there a restriction that prevents it?" and if it's ok, the server does the code and the player gets the update after it runs on the server.
"Run on Server" sends the command to the server from the client and runs it.
"Multicast" will execute only from the server, then send it to the clients so that it runs on their machines.
So, when the server presses Right Mouse, "Cli_Dash" runs. "Cli_Dash" is a multicast, but won't execute code on the clients because the "Switch has Authority" node will only let that code run on the server. There's no point in making it multicast if it can't run on clients as well. The server will set the replicated Dash boolean to on, then after a delay, turn it back off.
When the client presses Right Mouse, "SrvDashCall" runs. The "Switch has Authority" node doesn't do anything here, since we already know this RPC only happens on the server anyway. Then "Cli_Dash" runs and should execute on the server, in spite of the issues outlined in the prior paragraph.
The boolean should be updating correctly. Your state machine may have some kind of conflict going a different way.
Try this. On tick, use a "Switch has Authority" node and on Remote, use a Print String node set to last 0.5 seconds. Get the Dash boolean variable and plug it into the text node, which should automatically convert it to "true" or false". When you test the game, it'll spam in the corner but when you press the button, the client should read "true" and you can figure out if the problem is in the networking or not.
[Net Update Frequency] From the other post. "Min Net Update Frequency" determines how often your character updates. "Min Net Update Frequency" is how infrequent the character will update if the character has been idle. I'd recommend making sure that "Min Net Update Frequency" is set to the same as the normal "Net Update Frequency", which is set to 100.
answered Mar 26 '19 at 03:55 AM
Follow this question
Once you sign in you will be able to subscribe for any updates here