- Home /
Animations playing only in the Host and not on the clients - Unity Mirror Networking.
I already have the Network Transform and Network animator components attached. I have spawned the game object with the client Authority. Thanks in Advance.
Here is some of my code:
I have a button which sets a bool to true on click TauntScript.cs: -
public void taunt()
{
taunting = true;
Invoke("resetTaunting", 3);
}
private void resetTaunting()
{
taunting = false;
}
And My player has the following code : -
void Start()
{
tauntScript = FindObjectOfType<TauntScript>();
}
void Update()
{
taunt = tauntScript.taunting;
if(taunt)
{
taunting();
}
}
public void taunting()
{
animator = GetComponent<Animator>();
animator.SetBool("IsTaunting", true);
Invoke("ResetTaunt", 3);
}
public void ResetTaunt()
{
animator = GetComponent<Animator>();
animator.SetBool("IsTaunting", false);
}
Answer by fonan · Jun 09, 2021 at 02:23 PM
Hi. I have the same exact question. Seems like the NetworkAnimator is not synching. I kind of reached a solution, but it is a work around. I will tell you but it kind of works strange cause it makes the animations a bit weird (fps drop for me). I gave up on the network animator, so i synch the animation myself. Here is how:
Make a command in the server side that the client calls. In you case something like this:
[Command]
public void CmdTaunt()
{
//Check in the server if the player can taunt
RpcTaunt(); --> Call the RPC method to synch manually the animator
{
Make the RPC call. The rpc call comes from the server and runs in in every client
[ClientRpc] private void RpcTaunt(bool value) { animator.SetBool("IsTaunting", value); }
Cons of this method: I dont know why, but the animation framerate drops damatically. Im sorry not giving you a solution for your problem because as I said, I had the same problem. This workaround honestly sucks xD
ok, have new updates I made it work without framerate drops! And Rpc method not needed, just the network animator component!
Seems like the network animator component cannot access things like navmesh agents or things like that, so, in the update method I tried to turn it into a [Command] method and it worked! try using [Command] on your update method to send all the info to the server and you can delete the Rpc method is not necessary since the animator componets takes care of the sync for you.
And btw rememebr to take off the client authority checkbox in the animator component since the command directive makes the update method a server method.