Replicating animations, aim offset, and SetRelativeLocation

I know these kinds of questions might have been answered already, but I also have another problem that I haven’t heard anything about. I’m doing everything on Blueprints, by the way. I’m doing my function replication somewhat by the book, when the crouch key is pressed, I trigger an event running on the server that executes the rest of the crouch logic (in the image), and a boolean is set. That boolean sets another boolean in the animation blueprint, which triggers the crouching animation. Now, the case is, when I go try out the animation in the editor (I set the player count to 2, with a dedicated server) the animation plays in the owning client, but it also plays in the other player character. And, in the other client, the animation does not play at all, on any mesh. Pic related, my crouching code.

The same thing’s happening with the aim offset. The animation plays on both of the meshes in the client that looks up and down, but on the other client, nothing plays on both meshes. I need a method to separate animations per player, I thought the player index input in the Get Player Character function might do it, but it turns out it’s for local multiplayer. I’m not too sure how to do this.

Then, I also have another weird problem with the SetRelativeLocation function. I use his function due to the fact that when the capsule half height is set, the player character dipped below the ground level, so I set the location when the player triggers the crouch event. All works fine and dandy on the server’s side, but when crouching once, the movement is really shaky, and when uncrouching, and the player runs/walks backwards, the mesh gets its location set to the crouch location, and it switches to the standing one, intermittently. When moving forwards, sometimes it’s fine, sometimes it does that. I’m especially clueless about this one.

I’ve solved the trouble I had with the set relative location function, turns out you have to have two events, one that runs on server and the other that is a multicast, hooked up to the same logic. Furthermore, there has to be boolean variables that describe whether the character is crouched, standing or prone, and these variables must be set to RepNotify. In the functions, you should set the capsule height and relative location of the character mesh. But, I still have to solve the animation trouble. It must be something that is doable in C++ but not in Blueprints, because the default Speed and Is in Air variables do apply to the executing client, but custom ones don’t.

I’ve also tackled the animation replication stuff, finally. To control the variables that you have in the animation blueprint, you must have the same variables in your player script, which must be replicated. Then, set the variables in the animation blueprint at the same time you set the ones in the player one. First, you have to cast to your player script, and in the object input, you must place the output of the “Try Get Pawn Owner” function. But the aim offset trouble isn’t fixed yet.

Disregard the last line of my previous comment, aim offset finally replicates correctly. What should be done, is to use the logic provided in the official documentation, but instead of using the “Get Control Rotation” and “Get Actor Rotation” functions as the target of the Rinterp, you must use the Get Base Aim Rotation function. I’ll set this question as solved, now. Hope it helps anyone else.

Apparently I need an answer to this question to mark it as solved, not comments. Whatever, you can just read them above.

Hi!

I know this is an old question (and you’ve marked it as solved) however I am wondering if you still have the animation replication blueprint. I am trying to replicate crouching on the server but cannot get it to work. I have tried many ways including (I think) the way you state above.
Would you be able to share some screenshots of a working replicated crouch (or similar) blueprint?
I would really appreciate it!

Thanks :slight_smile:

I’ve been working quite a lot on this game of mine. I still do have the animation blueprint, in fact, I’ve expanded quite a bit on what I had before.

Here’s the logic on the player character.

And here’s that crouching logic. Basically, you need to set a boolean variable (Crouching) that replicates with RepNotify. You have to set it both in the owning client and in the server. Apart from this, you have to run the set relative location and set half height function in the owning client and the server as well. In the rep notify function, you have to do the same thing, that is, setting the relative location and the capsule half height again. In the animation blueprint, you just have to cast to the player character script and get the Crouching variable.