Hi, I've been testing multiplayer but I'm stuck on syncing the animation. I want to sync an attack animation that triggers on pressing the A key. So all I want to do is call an animation on all clients connected as well as the server. The issue I have is that the command calls it only on server side and not on any clients. Do I have to do an RPC call inside the Command or something? Code (CSharp): void UpdateInput() { if (Input.GetKeyDown(KeyCode.A)) { CmdDoAttack(); } } [Command] void CmdDoAttack() { _anim.SetTrigger("Kick"); }
yes you could do it like: Code (CSharp): void UpdateInput() { if (Input.GetKeyDown(KeyCode.A)) { CmdDoAttack(); } } [Command] void CmdDoAttack() { // check if player can attack if (isDead) return; RpcAttack(); } [ClientRpc] void RpcAttack() { _anim.SetTrigger("Kick"); }
Thanks seanr, that worked but it wasn't calling it on the server side - had to make a small change. I feel like they should have a way to send to the server + all clients instead of doing this but I guess this is not too bad. Code (CSharp): [Command] void CmdDoAttack() { if (isDead) return; _anim.SetTrigger("Kick"); RpcDoAttack(); }
ClientRpc calls are supposed to be called on the host. That is bug: http://issuetracker.unity3d.com/iss...-for-local-client-for-networked-scene-objects That is fixed in 5.1p1. You have the right workaround for now.
From what I can tell, even on 5.1.0p1 ClientRpc and SyncEvent aren't calling on a local host for networked scene objects.