Hi all! I have a melee attack animation that has an Anim Notify State. That notify state fires both on Server and Client, because of that, the code runs twice.
The animation is running through two events, a Client and a Server event, just to replicate it, and that works.
This happens when I play the animation once (On left mouse click), it prints the “Hello” string 8 times, the funny thing is that when the attack animation also did damage, it did it twice not 8 times (but of course still not good).
Okay, I see the first problem. The animation update fires on tick, so using a print string anywhere is going to spam whatever you are printing.
I don’t know what all else you have going on in this project, but I would consider trying to hook that attack call up to some different functionality. Is this “attack started” bool just triggered off of an anim-notify? You could just hook the whole thing up to the anim notify then and don’t even need the update animation node.
Usually you shouldn’t hook entire attacks into the animation graph. The animation graph is strictly for setting variables used for the state machine. Other kinds of logic usually go other places instead.
That variable is from C++ Character Class, it gets set to true when I click the left mouse button.
I thought of that, feels counter intuitive to do that, but didnt find anything better yet. Where else should/could I set up the functionality for attacking? Should the “Play Montage”-s stay there?
I thought of that, feels counter intuitive to do that, but didnt find anything better yet. Where else should/could I set up the functionality for attacking? Should the “Play Montage”-s stay there?
Well, usually attacks would be hooked into the main character and the input would start the attack just from being pressed. No bools would be needed.
Hmm, I’ll try that tomorrow when I have time, thanks!
That was from when I was guessing your bool was set in an anim notify. You don’t even need that now lol
You say you press a button to set the bool. Unreal Engine already comes with inputs though. You should set up the inputs to attack when you press the button, no variables needed.
Also, this is only fixing a few other problems I just happened to notice. Your “main” problem of the server/client double firing will still be there. I don’t know much about multiplayer, but I’m sure you can find a youtube video or documentation somewhere that will explain how to multiplayer.
Well, I know a few things how mp works in unreal, but still not 100% sure when and how exactly to setup things in different situations. For example the client attacks only once, or thats how it seemed first, it attacks once, because it cant run server functions, but those function are also executed on client too, but if I play with 2 clients and 1 server, then the second client fires the attack three times instead of one or two, so “maybe” there is something thats definetely wrong
Yes, I’m using the inputs in the CPP as well, I just wanted to communicate between cpp and bp with a variable that gets set when the input fires.
Okay, I think I get what is happening here now. You already have an attack input, but you just want to attach an animation to it. If that is the case, I would recommend using a Blueprint Implementable Event in C++ for the anim montage. Then simply put that into your function for your attack input.
Omg, probably thats what I need, thank you @Detach789! I only had enough time to try out how it executes, and its exactly what I want. I’ll update the post when I have time and fix it. Thanks again
You are running client and server under a single process. In the advanced setting of multiplayer uncheck “use single process”.
They should be split into two instances not interjecting messages into the same process.
Hmm, I think I found what you mean it is Run Under One Process, I unticked it, now it launches two instances, but now the code I wrote before looks like is broken. It does work, but artifacts. For example I had a functionality to pickup certain objects and move them around, now when I pick it up (either server or client) it glitches everywhere on the screen, and also now the attack on click starts, then doesnt end until I click again, which was before different, it only ran once when I clicked once.
And it also seems like I have insane ping.
Is there any fix for that or I need to redo the code or fix it or something?
I also have an idle animation after equipping the weapon, should that also be fired off of an event after equipping? Or just update the animation to that just like it was before? Because it seems more work to code Idle animation than update it in “Event Blueprint Update Animation”.
Looks like the problem is with multicasting, I multicast the attack animation to all clients, then run it on server, if I dont multicast it, then it doesnt show the animation but runs once. If I multicast it, then it runs on all clients and server, but it deals damage as many times as many clients are running.
AttackOnServer is set to Run On Server while AttackOnClient is set to Multicast (both reliable)