Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Unity Multiplayer Animator.SetTrigger/NetworkAnimator.SetTrigger Bug?

Discussion in 'Connected Games' started by DRRosen3, Dec 1, 2015.

  1. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    I'm a bit confused about the functionality and purpose between the Animator component and the NetworkAnimator. From my understanding since the debut of 5.0, the NetworkAnimator was simply responsible for relaying the state of the Animator's parameters across the network. ...and that's how I've been using it to date. However, with the recent addition to the Animator of .SetTrigger I've switched from using booleans to trigger certain Animator states to using triggers. Therein lies my problem/confusion. Everything works properly up until the point of needing to synchronize triggers over the network. My speed parameter determines if the player is idle, walking, or running. Via script I modify it (on the client that has authority) using Animator.SetFloat(). This works just fine. On all other clients the animation is synchronized. However, when I use Animator.SetTrigger() for attacks, the animation is not synchronized. The animation occurs on the client, but it does not happen on the server or on other clients.

    I've looked into using NetworkAnimator.SetTrigger(). This DOES synchronize the proper animation to the server and other clients. However, it's a bit wonky. It's as is the animation starts, and then a few frames into it, it resets and starts again.
     
    Smuggler20 likes this.
  2. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,193
    I am struggling with syncing animations right now too, and I was using the Network Animator on my objects, and (like you), my characters animate according to their velocity (or speed). I noticed the same "reseting" of the animation, and my guess was that because of the latency between clients and server, the client sees the object as moving at a fluid velocity, whereas the server only gets that data in chunks (with delays inbetween). I'm guessing this causes the server to see your object as having "zero" speed for short amounts of time -- and thus the choppy animations.

    To fix this (for my part) I stopped using velocity to determine animations, and simply started using booleans. That is, if my unit/character has a path, I play the run animation, if it doesn't I stop the animation. This worked for me. But then you have to stop using velocity for animations (which is a dirty solution, but it worked for me).

    As for your Animator trigger problem, I don't know yet, sorry. I'm still trying to get the Network Animator to sync animations properly when I have "Local Player Authority" checked on my objects. Currently it's not syncing animations between all clients and the server.
     
  3. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
  4. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    A bit of an update... So I forgot to change the transitions for these animations. They transition from the ANY state...and I unchecked "Can Transition from Self". That fixed it a little. Now it doesn't start and then restart a few frames in. Now...using NetworkAnimator.SetTrigger()...it plays the animation...but it plays it twice.

    EDIT - This only happens on the server...not connected clients. So the player acting as the server...their character performs the animation twice. Connected clients only perform the animation once.
     
  5. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    Still struggling with this. Trying to isolate the problem I went back to using Animator.SetTrigger(). I tested it both as a client and as a host. The animation plays properly on the Local Player, but for anyone else observing it doesn't play...BUT...it DOES execute. I know this because there's an animation event on the animation. And the event executes on the server if the animation is coming from the client. Come on...SOMEBODY else must be going through this or have gone through it.
     
  6. Chris-Clark

    Chris-Clark

    Joined:
    Jan 16, 2012
    Posts:
    128
    That's interesting. I had just assumed that normal triggers were not synced with that component. But if your event is firing then it must be a bug in unet that's just not playing the animation?
     
  7. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    I don't know. I mean with UNet still in development the docs aren't really clear.

    http://docs.unity3d.com/Manual/class-NetworkAnimator.html
    http://docs.unity3d.com/ScriptReference/Networking.NetworkAnimator.SetTrigger.html

    This is confusing to me because the NetworkAnimator page says that the component syncs ALL animations (float, int, bool, and trigger). But then why do you need the NetworkAnimator.SetTrigger() function if the NetworkAnimator already synchronizes Animator.SetTrigger() if the NetworkAnimator is set to auto-send that parameter? Only other information I could find was here...

    http://forum.unity3d.com/threads/un...w-do-i-use-networkanimator-settrigger.351214/

    ...and I don't think he has a clue what he's doing either, because he's setting the trigger on both the Animator and the NetworkAnimator. And like I said above, using the NetworkAnimator.SetTrigger() causes the animation to play twice for the Local Player (if the Local Player is the host)...and not at all for other observers.
     
    Last edited: Dec 5, 2015
  8. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
  9. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    @hashashin You haven't supplied nearly enough information for anyone to be of any help to you. What parameters does your walk animation use for transitioning? Bool? Float? Int? Trigger? Is the parameter for walk set up to AutoSend? (If you don't know what this is you haven't looked over the docs for the NetworkAnimator enough).

    In any case, unless your walk animation uses a Trigger parameter, this isn't the thread for you to seek help in. This thread is specifically for determining whether Triggers are properly synchronized across the network using the NetworkAnimator if you use Animator.SetTrigger(), or if there is a bug in NetworkAnimator.SetTrigger().
     
  10. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    Almost 250 views and nobody else has encountered this problem? o_O
     
  11. a-bottosso

    a-bottosso

    Joined:
    Nov 13, 2015
    Posts:
    8
    Hi, I solved this problem with a workaround, unchecking the trigger on the NetworkAnimator list and manually setting the trigger (standard animator), using a Command (in local player) that call a ClientRPC on all the other client instances.
     
  12. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    While I already knew about that "work around" I appreciate it anyway @a.bottosso . Still would love to hear from someone on the Unity team about this.
     
  13. Cha0os

    Cha0os

    Joined:
    Feb 22, 2014
    Posts:
    17
    I'm having the same problem... doesn't seem to be solved by the latest patch. Every triggered animation is played twice on a hosting player's game.

    Any progress?
     
  14. deliciousbees

    deliciousbees

    Joined:
    Mar 16, 2015
    Posts:
    4
    We hit this today and found a pretty hilarious fix: disable localPlayerAuthority on any NetworkIdentity that's controlled by a player on the server.

    This gets rid of the doubling of animations, and at the same time does not remove player control/authority for the server players (I'm guessing because it's the server and it's special).

    Anyway, hope this helps other people who google "NetworkAnimator double animations", and I'm looking forward to editing this when it breaks in some random update in the future :)
     
  15. everystone

    everystone

    Joined:
    Jan 30, 2014
    Posts:
    6
    Im having the same issue, SetTrigger on Network Animator plays animations twice. Fixed it using a.botosso's rpc workaround for now. Client calls CmdSetTrigger(str), and on server it calls RpcSetTrigger(str).

    I guess another workaround would be to have a SyncedVar named TriggerStr, with a hook that runs SetTrigger().
    On a side note, after I started experimenting with Unet, unity editor has been crashing alot, do you guys notice that too?
     
  16. Khoros

    Khoros

    Joined:
    Mar 1, 2016
    Posts:
    7
    Yep, same problem here, triggers are not syncing AT ALL for me
     
  17. Zenov

    Zenov

    Joined:
    Jul 28, 2014
    Posts:
    50
    Bump.
    I was having the same issue with the network animator.
    I used the workaround as suggested but I'm curious why this hasn't been taken care of. Isn't this a bug?
     
    Last edited: May 10, 2016
  18. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    54
    Animations still triggered twice and also Animator.SetLayerWeight is not working properly...
     
  19. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    Yep. It is a bug, but it seems to be one the dev. team doesn't seem keen on identifying/addressing.
     
  20. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    10
    Can you try to use the NetworkAnimator.setTrigger("trigger name")?
    For example I have something like this:
    Code (csharp):
    1.  
    2. private void UpdateAnimator(Vector2 input)
    3. {
    4.   animator.SetFloat("forward", input.y);
    5.   animator.SetFloat("horizontal", input.x);
    6.  
    7.   if (CrossPlatformInputManager.GetButtonUp("Jump"))
    8.   {
    9.     animator.GetComponent<NetworkAnimator>().SetTrigger("jump");
    10.   }
    11.  
    12.   animator.SetBool("grounded", characterController.isGrounded);
    13.   animator.SetBool("walking", CrossPlatformInputManager.GetButton("Walk"));
    14.   animator.SetBool("crouching", isCrouching);
    15. }
    16.  
    and in network setup:

    Code (csharp):
    1.  
    2. public override void OnStartLocalPlayer()
    3. {
    4.   //forward
    5.   GetComponent<NetworkAnimator>().SetParameterAutoSend(1, true);
    6.   //horizontal
    7.   GetComponent<NetworkAnimator>().SetParameterAutoSend(2, true);
    8.   //crouching
    9.   GetComponent<NetworkAnimator>().SetParameterAutoSend(4, true);
    10.   //jump
    11.   GetComponent<NetworkAnimator>().SetParameterAutoSend(6, true);
    12.   //grounded
    13.   GetComponent<NetworkAnimator>().SetParameterAutoSend(8, true);
    14.  
    15. }
    16.  
    17. public override void PreStartClient()
    18. {
    19.   //forward
    20.   GetComponent<NetworkAnimator>().SetParameterAutoSend(1, true);
    21.   //horizontal
    22.   GetComponent<NetworkAnimator>().SetParameterAutoSend(2, true);
    23.   //crouching
    24.   GetComponent<NetworkAnimator>().SetParameterAutoSend(4, true);
    25.   //jump
    26.   GetComponent<NetworkAnimator>().SetParameterAutoSend(6, true);
    27.   //grounded
    28.   GetComponent<NetworkAnimator>().SetParameterAutoSend(8, true);
    29. }
    30.  
     
  21. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    That's not how the NetworkAnimator is designed to function.
     
  22. ChrisKurhan

    ChrisKurhan

    Joined:
    Dec 28, 2015
    Posts:
    10
    I agree it is not intuitive, or necessarily correct, to do it this way - but it does resolve the problem for me.
    I stumbled across this thread because I had the same problem as several users here. Since this resolved the "trigger not synchronizing across network" issue, I have shared it.
    Have you opened a bug report about this already?
     
  23. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    628
    Yes I opened a report months ago...but this doesn't solve the issue that I bring up. Using the method you're doing, causes the animation to occur twice on the server (when the character performing the animation IS the server).
     
  24. SonawHeaven

    SonawHeaven

    Joined:
    May 10, 2014
    Posts:
    1
    I've been having the same problem as well. As this was the only thread consistently popping up on the subject I'm sharing here my solution (Unity v5.3.5):

    Use the network animator to sync any non-trigger variables, and to sync the trigger, always call a command that checks if the player using the command is server. If it isn't then you set the animator locally, and then call an RPC to set the animator on all instances. If the player calling the command is server then you simply just call the aforementioned RPC.

    Example code (C#) (sorry for not being formatted):
    [Command]
    public void CmdSetAnimTrigger(string triggerName)
    {
    if(!isServer)
    {
    animator.SetTrigger(triggerName);
    }
    RpcSetAnimTrigger(triggerName);
    }

    [ClientRpc]
    public void RpcSetAnimTrigger(string triggerName)
    {
    animator.SetTrigger(triggerName);
    }

    Still i wish the dev team would sort this out, so we could just tick a box and not have to worry about syncing trigger on the scripting side of things. Also if this was mentioned before in this thread, sorry for repeating.
     
    schkorpio likes this.
  25. Zenov

    Zenov

    Joined:
    Jul 28, 2014
    Posts:
    50
    Yes that would be nice. It seems to defeat the purpose of having a network animator component if you have to manually sync it lol
     
    pixonic42 and schkorpio like this.
  26. schkorpio

    schkorpio

    Joined:
    Apr 15, 2015
    Posts:
    13
    Thanks all, helped a lot :)
     
  27. bazzer

    bazzer

    Joined:
    Nov 9, 2012
    Posts:
    7
    I came across the anim trigger issue and resolved it by using an NetworkAnimator.ResetTrigger(''Anim Name") immediately AFTER the NetworkAnimator.SetTrigger("Anim Name") call.

    void GetInput()
    {
    // ATTACK 1
    if (Input.GetButtonDown("Fire1")) CmdAttack1();
    }

    [Command]
    void CmdAttack1()
    {
    RpcAttack1();
    }

    [ClientRpc]
    void RpcAttack1()
    {
    netAnim.SetTrigger("Attack1");
    netAnim.animator.ResetTrigger("Attack1");
    }

    Hope that helps.
     
  28. Jeff-Rosenberg

    Jeff-Rosenberg

    Joined:
    Oct 23, 2012
    Posts:
    26
    I'd like to add my own findings on the subject.

    If you want to sync a parameter you can add the NetworkAnimator component, check the parameter in the inspector, and use your Animator component normally on objects with local authority. For triggers you need to use NetworkAnimator to set the trigger; checking a trigger in the NetworkAnimator's inspector doesn't seem to do anything.

    Code (CSharp):
    1. private void Update()
    2. {
    3.     if (isLocalPlayer)
    4.     {
    5.         Vector3 input = new Vector3(Input.GetAxis("Horizontal"), 0f, Input.GetAxis("Vertical"));
    6.         animator.SetFloat("Horizontal", input.x); // This syncs correctly
    7.         animator.SetFloat("Vertical", input.z); // This syncs correctly
    8.  
    9.        if (Input.GetButtonDown("Fire1"))
    10.         {
    11.             networkAnimator.SetTrigger("Attack"); // This syncs correctly
    12.         }
    13.     }
    14. }
    The problem comes in when you want the server to handle the animations, for example:

    Code (CSharp):
    1. private void Update()
    2. {
    3.     if (isLocalPlayer)
    4.     {
    5.         if (Input.GetButtonDown("Fire1"))
    6.         {
    7.             CmdAttack();
    8.         }
    9.     }
    10. }
    11.  
    12. [Command]
    13. protected void CmdAttack()
    14. {
    15.     // Set the trigger here once I've verified that the player can attack and have dealt damage
    16. }
    Anything called in my CmdAttack method is called on the server, so any changes to an Animator or NetworkAnimator are done on that machine. This means that even if Client A has authority, Host B doesn't have authority and NetworkAnimator won't send messages properly.

    The solution then is to use a ClientRPC on the server to tell each client when to set the trigger and bypass NetworkAnimator altogether in that case:

    Code (CSharp):
    1. [Command]
    2. protected void CmdAttack()
    3. {
    4.     // Verification, hit detection, and damage
    5.     RpcSetTrigger("Attack"); // Animate clients
    6. }
    7.  
    8. [ClientRpc]
    9. public void RpcSetTrigger(string trigger)
    10. {
    11.     animator.SetTrigger(trigger);
    12. }
    13.  
    You can reproduce the "host triggers twice" bug mentioned by @DRRosen3 by replacing RpcSetTrigger("Attack"); with networkAnimator.SetTrigger("Attack");

    The [Command] mentioned by @SonawHeaven (CmdSetAnimTrigger) has a few flaws: the isServer check will always be false because Commands are only called on the server. Instead you can use a NetworkAnimator to set the trigger from the client with authority like in the first example. The Rpc, however, is great. Use that whenever you want the server to trigger an animation.
     
    ChrisKurhan likes this.
  29. Jeff-Rosenberg

    Jeff-Rosenberg

    Joined:
    Oct 23, 2012
    Posts:
    26
    After thinking about this some more in the shower, I think it comes down to how we structure our calls. We want to have our calls split into 2 groups:
    1. Important/Secure calls done on the server
    2. Unimportant/Insecure calls done on the clients
    Our animation triggers can fall into either category, but should probably be in the former. For example, I don't want a hacked client to be able to spam animation triggers (lets say emotes) across the network.

    With that in mind, my above code using CmdAttack and RpcSetTrigger is probably not correct, since the RpcSetTrigger only handles generic triggers. What I really want to do is this:
    1. Send an input command to the server (Command)
    2. Check that the command is valid
    3. Apply the effects of the command on the server
    4. Send a confirmation command to all clients (ClientRpc)
    My code ought to be:
    Code (CSharp):
    1. [Command]
    2. protected void CmdAttack()
    3. {
    4.     if (!CanAttack) // Check that the player is able to attack
    5.     {
    6.         return;
    7.     }
    8.     // Damage and hit detection
    9.     RpcAttack(); // Notify clients
    10.     attackCooldown = attackDelay;
    11. }
    12.  
    13. [ClientRpc]
    14. public void RpcAttack()
    15. {
    16.     onAttack.Invoke(); // My animator trigger, sounds, particles, etc are all linked to this from the Inspector
    17. }
    I'd then do this any time I want a behaviour verified/performed on the server. Adhering to that kind of structure (CmdXYZ and RpcXYZ) is pretty clear in intent and should keep things pretty simple. Important things like confirmation and application of effects happen in the Cmd, while unimportant things like visuals happen in the Rpc.

    Ideally I'd also like to remove the NetworkAnimator altogether. The NetworkAnimator doesn't lerp floats, which makes blendtrees look chunky if you're syncing the blend parameters. I'd much rather have it structured so I don't need to sync those kinds of parameters in the first place by calculating my Animator's parameters locally. I almost have this working, too, but I'm having a hard time finding a reliable velocity to reference. CharacterController.velocity is good, but needs to be smoothed and can end up with strange values on non-local player authority objects (other player's characters).

    If my animator's parameters/triggers aren't important I can just use a NetworkAnimator for my parameters/triggers, and make sure that when I set the trigger/parameter I'm doing so only for objects with local player authority.
     
    Last edited: Sep 21, 2016
    ChrisKurhan likes this.
  30. a-lomo

    a-lomo

    Joined:
    Aug 5, 2012
    Posts:
    12
    This definitely appears to be a bug. A workaround that worked for us was to set the trigger on the NetworkAnimator and immediately ResetTrigger on the Animator if run on the server. This makes it so you don't have to use your own Commands and Rpc.

    Code (CSharp):
    1. networkAnimator.SetTrigger(triggerName);
    2.  
    3. if (NetworkServer.active)
    4.     animator.ResetTrigger(triggerName);
    This is on an object that is set to have local authority. This addresses the issue with the animation getting triggered twice if running as a Host. Hope that helps!
     
    s26812743 and Chris-Clark like this.
  31. deadopinion569

    deadopinion569

    Joined:
    Sep 17, 2016
    Posts:
    4
    357 days from the op post (8 days from being a year!... this is really sad)

    I've too found this issue with the Unity Network Animator, where triggers are not working on the network (works fine on the client)

    Steps to reproduce the issue / problem
    1. Setup a player with an animator with one of the following type perimeters: bool, trigger (other perimeters can have this issue too, just not that easy to see)
    2. Add Network Manager in the scene and add Network Animator to the player and set Local Player Authority
    3. Build and Run, bool and trigger perimeters just doesn't seems to sync


    From what I've tested, it is a lag / delay / packet drop / sync issue. Animations just doesn't get sent to the Network Animator when it is too fast of a trigger (how can pinging local at 32ms can still lag, I don't know). My current way around is to change it from being a trigger to a bool and make sure it stays there for the duration of the animation in script, which probably not the best way (if I set it too long, it will loop, causing double animator trigger).

    So, I'll be trying those work around you guys have. You guys are the best.


    Since this is like a fundamental problem in unity (dealing with packet drop), Unity devs are unlike to have a good fix, but at least they really should have shown their concern or provide a documented work around.
     
  32. joschi27

    joschi27

    Joined:
    Jul 31, 2016
    Posts:
    8
    Bump. This is ANNOYING.
     
  33. ZenTeapot

    ZenTeapot

    Joined:
    Oct 19, 2014
    Posts:
    7
    Trigger not syncing. I'm hitting this issue as well. Is unity dead or something? Do they still support the unet API?
     
  34. guybro_thunderboots

    guybro_thunderboots

    Joined:
    Aug 27, 2015
    Posts:
    17
    > Trigger not syncing. I'm hitting this issue as well. Is unity dead or something? Do they still support the unet API?

    I'd like to know this too -- and if there are any other long-standing bugs in Unity Multiplayer. We made the decision to adopt Unity for productivity, but it's not reassuring to see bugs this old go unacknowledged.
     
  35. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    260
    Really disappointing that nobody in the Unity Team replied to this thread yet :/
     
  36. s26812743

    s26812743

    Joined:
    Jan 23, 2017
    Posts:
    3
    thank you for this! Super simple and easy and works perfectly.. I know its a work around but if you have this problem with triggers on your network animator TRY THIS
     
  37. mikeownz

    mikeownz

    Joined:
    Mar 3, 2017
    Posts:
    20
    Hmm. Maybe the docs have been updated since this post, but it does say that the NetworkAnimator.SetTrigger will be called on the server and all clients if local authority is set. So it makes sense that you would see double animation if you are the host, since you are both server and a client. You don't notice this when you change the bool parameters for example, because setting something equal to true twice does not impact anything. But having two triggers would.

    I do not think this is a bug and that it is intentional, but does come off clunky if you intend on using a host instead of a dedicated server. The docs could do a better job of warning of potential misuses in the case of hosting vs. running a dedicated server.

    Obviously if you have a dedicated server instead of a host, then I would imagine things would work out perfectly. Otherwise if you are the host, you need to do some additional tweaking.

    Since I am hosting and not using a dedicated server, I am debating on using the NetworkAnimator.SetTrigger along with resetting the trigger if on host after calling the trigger vs. just using a command and RPC with the trigger name as an input string.


    https://docs.unity3d.com/ScriptReference/Networking.NetworkAnimator.SetTrigger.html
    https://docs.unity3d.com/ScriptReference/Networking.NetworkAnimator.html
     
    Last edited: Mar 8, 2017
  38. allcoder

    allcoder

    Joined:
    Jun 4, 2015
    Posts:
    13
    Bump ! the bug still alive! :/

    I change my Trigger param to Boolean and did the true/false logic in the code to simulate the trigger. With this change sync fine.

    Code (CSharp):
    1.  
    2. if (Input.GetButton("Attack1"))
    3. {
    4.      isAttacking = true;
    5. }
    6.  
    7. if (Input.GetButtonUp("Attack1"))
    8. {
    9.      isAttacking = false;
    10. }
    11.  
    12. animator.SetBool("Attack", isAttacking);
    13.  
     
    Last edited: Apr 3, 2017
  39. Abhiroop-Tandon

    Abhiroop-Tandon

    Joined:
    Oct 2, 2014
    Posts:
    3
    I don't know about the two animations playing, `netAnim.SetTrigger(trigger);` on my NPC wont even play the animation neither on client nor on the server. My player animations are synced fine and i am not even using `netAnim.SetTrigger(trigger)` there (Touch wood) but then i have my NPC's animations and i just cannot make the triggers trigger the animation. If i use `GetComponent<Animator>().SetTrigger(trigger);` on my NPC then it does play the animation but wont sync it.

    Could anyone suggest any workarounds ??

    PS i did try the `RpcSetTrigger(string trigger)` but it didn't work as well

    EDIT (Fix) - i feel very stupid after this because i've wasted 3 days trying to solve this :( Anyways the way i solved it is on my NPC's network identity i unchecked both the boxes and tadaaa its working.
     
    Last edited: Apr 4, 2017
  40. allcoder

    allcoder

    Joined:
    Jun 4, 2015
    Posts:
    13

    Hahaha, yeah, is normal dont worries xD
     
  41. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    62
    Yeah, I'm still coming across the same issue..

    For me, the NetworkAnimator's SetTrigger works great with syncing trigger parameters across the network, but does cause animations to happen twice in a row.

    Also, there's no SetBool, SetFloat, etc. in NetworkAnimator, so I try using my Animator's methods to set parameters. In the inspector, I see that all of my parameters from my Animator component are checked in the NetworkAnimator to be synchronized across the network, but my boolean parameters are not being synced.

    Hopefully Unity addresses this all soon. For now, I'll just use Commands and RPCs or Network Messages to update the parameters
     
    MichaelJT likes this.
  42. MichaelJT

    MichaelJT

    Joined:
    Jan 28, 2015
    Posts:
    5
    This is an issue with a trigger not resetting after being triggered despite the fact that's exactly what it's supposed to do.

    I have 3 animation states - Idle, Attack 1 and Attack 2.

    I can go from:
    - Idle to Attack1
    - Attack1 to Idle
    Attack1 to Attack2
    Attack 2 to Attack1

    I literally have to reset the Trigger manually in 4 seperate areas to stop the animation from repeating when I don't want it to.
     
  43. allcoder

    allcoder

    Joined:
    Jun 4, 2015
    Posts:
    13
    Yeah, i did that fix too
     
  44. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    356
    any update to this? still having the issue
     
  45. anduhd

    anduhd

    Joined:
    Dec 7, 2016
    Posts:
    1
    2017 and Unity isn't capable of having a working networking component. Photon is way ahead, and other 3rd party network components. I can't understand why all the parameters sync on the network using Animator but the trigger doesn't and needs NetworkAnimator.setTrigger!!!!
     
  46. BRKENT

    BRKENT

    Joined:
    Aug 4, 2017
    Posts:
    13
    BUMP. Waiting for a resolution for this too.. They need to fix this xD or show us how!
     
  47. S4UC1SS0N

    S4UC1SS0N

    Joined:
    May 29, 2014
    Posts:
    27
    Calling "animator.ResetTrigger("TriggerName");" right after did the trick, thank you for the workaround, still, it's a bit disapointing a bug like this can still not be fixed after more than a year.
     
  48. plutoshe

    plutoshe

    Joined:
    Oct 24, 2017
    Posts:
    1
    I faced the same problem due to NetworkAnimator.SetTrigger triggers the variable twice.
    Thank you for suggest "call "animator.ResetTrigger("TriggerName")"". It is a nice trick.
     
  49. pondo

    pondo

    Joined:
    Mar 22, 2015
    Posts:
    4
    Since the UNet source code is available online I figured I'd stop guessing and just dig into it. If you have the source, go to the tip (currently revision 21, 6047ccb13d56) and you can follow the line numbers in NetworkAnimator.cs.

    Here's a summary of my findings:
    • Calling SetTrigger from a NetworkAnimator with localPlayerAuthority sends a message to the server with its netId and the trigger's hash (line 359)
    • Server handles message. It looks for the NetworkAnimator and, if it exists, proxies the same message to all the ready clients (line 430)
    • The clients then handle the message. Each client looks for the NetworkAnimator and, if it exists, calls SetTrigger() on the the regular Animator component referenced by it (line 479)
    So far so good. The problem is that when the server handles the message, it doesn't just proxy the message. It also calls HandleAnimTriggerMsg (line 428) which is the same function used by clients to actually fire the trigger. In a host setup, when handling the message on the server side it will fire the trigger (via HandleAnimTriggerMsg), then proxy the message back to itself, which will fire the trigger again when handled as a client.

    Maybe I'm missing something but this really doesn't look like intended behaviour and it would be very easy to fix.
     
  50. firegate666

    firegate666

    Joined:
    Nov 20, 2015
    Posts:
    8
    Wow, this is quite a journey here. I can add myself with the same issue. Animations played twice but on the joining client.

    I use the NetworkAnimator to set Triggers, I don't use value parameters

    Code (CSharp):
    1.  
    2.         _isAttack1 = Input.GetButtonDown("Fire1");
    3.  
    4.         if (_isAttack1)
    5.         {
    6.             _characterAnimator.SetTrigger("Attack_1");
    7.             _networkAnimator.SetTrigger("Attack_1");
    8.         }
    9.  
    When I start this code now in host mode, everything is fine. The animation plays on the host and it plays on the joining client.

    Triggering an attack on the joining client, plays the animation once on the remote host and twice on the client

    You can watch here how it looks like:


    Funny though that using the Command Pattern fixes it for me as well, but I am still interested what I am doing wrong with the NetworkAnimator

    Code (CSharp):
    1.  
    2.     void ApplyInput()
    3.     {
    4.         if (_isAttack1)
    5.         {
    6.             CmdAttack1();
    7.         }
    8.     }
    9.  
    10.     [Command]
    11.     protected void CmdAttack1()
    12.     {
    13.         // Verification, hit detection, and damage
    14.         RpcSetTrigger("Attack_1"); // Animate clients
    15.     }
    16.  
    17.     [ClientRpc]
    18.     public void RpcSetTrigger(string trigger)
    19.     {
    20.         _characterAnimator.SetTrigger(trigger);
    21.     }
    22.  
     
    Last edited: Dec 5, 2018