Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
Dismiss Notice
Join us now in the Performance Profiling Dev Blitz Day 2023 - Q&A forum where you can connect with our teams behind the Memory and CPU Profilers and the Frame Debugger.

Unity Multiplayer Synced Animation on Command?

Discussion in 'Multiplayer' started by fpwong, Jun 12, 2015.

  1. fpwong

    fpwong

    Joined:
    Jun 12, 2015
    Posts:
    5
    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):
    1. void UpdateInput()
    2. {
    3.      if (Input.GetKeyDown(KeyCode.A))
    4.      {
    5.             CmdDoAttack();
    6.      }
    7. }
    8.  
    9. [Command]
    10. void CmdDoAttack()
    11. {
    12.     _anim.SetTrigger("Kick");
    13. }
     
    Last edited: Jun 12, 2015
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    yes you could do it like:

    Code (CSharp):
    1. void UpdateInput()
    2. {
    3.      if (Input.GetKeyDown(KeyCode.A))
    4.      {
    5.             CmdDoAttack();
    6.      }
    7. }
    8. [Command]
    9. void CmdDoAttack()
    10. {
    11.     // check if player can attack
    12.     if (isDead)
    13.         return;
    14.        
    15.     RpcAttack();
    16. }
    17.  
    18. [ClientRpc]
    19. void RpcAttack()
    20. {
    21.     _anim.SetTrigger("Kick");
    22. }
     
    fpwong likes this.
  3. fpwong

    fpwong

    Joined:
    Jun 12, 2015
    Posts:
    5
    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):
    1. [Command]
    2. void CmdDoAttack()
    3. {
    4.     if (isDead) return;
    5.     _anim.SetTrigger("Kick");
    6.     RpcDoAttack();
    7. }
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  5. CorruptedHeart

    CorruptedHeart

    Joined:
    May 4, 2010
    Posts:
    379
    IsSyncEvent supposed to not fire on a local host for networked scene objects?
     
  6. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    it is supposed to fire on the host also.
     
  7. CorruptedHeart

    CorruptedHeart

    Joined:
    May 4, 2010
    Posts:
    379
    From what I can tell, even on 5.1.0p1 ClientRpc and SyncEvent aren't calling on a local host for networked scene objects.