Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

NetworkAnimator + Multiple Animator Controller Layers? Broken?

Discussion in 'Multiplayer' started by Zullar, May 5, 2016.

  1. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    5.3.4p5
    Is the Network Animator supported for multiple animator layers?

    I have an object with 3 layers in the Animator Controller to allow:
    1: Walking
    2: Walking + Blocking
    3: Walking + Attacking
    4: Walking + Blocking + Attacking
    5: Standing
    6: Standing + Blocking
    7: Standing + Attacking
    8: Standing + Blocking + Attacking

    It works fine on the server/host.


    However, on a client using NetworkAnimator only the lowest priority base layer [0] (top in the hierarchy) walking animation works. The attack and block animations on layer [1] and [2] are not working on client.

    Has anybody successfully used NetworkAnimator on an Animator Controller that has more than 1 layer? Thanks in advance.
     

    Attached Files:

  2. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Did you try starting a server with a build, and connecting as a client with the editor? you'd be able to select the client prefab in the editor then and view the animator live to see if the parameters are syncing. Are the layer weights set to 1.0 on the remote prefab?
     
    Zullar likes this.
  3. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    A good thought. I did connect with client in editor. The layer weights are properly set to 1 on the client. But the state remains in the "None/Default" state, it does not switch to the "Blocking" state when Animator.CrossFadeInFixedTime() is called on the server. Animator.Play() also does not work.

    If I switch the Block layer to layer[0] then it works just fine, but layers [1] and [2] do not work.

    Might be able to get things to work with some convoluted integer parameter that triggers entering certain states (since parameters seem to sync properly) but at that point I'd just as well scrap the NetworkAnimator completely and just use messages/RPC.

    Has anybody successfully gotten NetworkAnimator to work on a Animator Controller with multiple layers? I am looking to know if I'm doing something wrong or if the NetworkAnimator component is just broken. Thanks
     
  4. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I think in its default state its only meant to sync parameters. The docs do show that it has a "playAnimsDirectly" flag you can set, I don't think I've seen that in the inspector though, you'd have to try it from script.

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

    EDIT: looking at the NetworkAnimator source on bitbucket, it looks like that property doesn't exist, even though the manual lists it. Weird.
     
    Last edited: May 6, 2016
    Zullar likes this.
  5. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    I am looking at the 5.4 notes and there is no mention of a fix for this. And also I do not see this on the bug list (I reported it, but it's not on the list yet).

    Does anybody use UNET's NetworkAnimator with multiple animator layers?
     
  6. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    I have the same problem, i need the layer weight and masks animated also over the network, because I have masks and the layer weight control which masks get turned on for example when player holding a gun and aiming, the basic upper body mask changes so that he can hold the gun while walking for example. Maybe we have to sync that ourselves by sending commands and rpc?
     
    Zullar likes this.
  7. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    Yeah. I think commands/RPC would work.

    But instead of bandaiding the parts of UNET's NetworkAnimator that are broken I think I might create a NetworkBehaviour Animator wrapper and just abandon the NetworkAnimator completely.

    I can't decide if I should wait and see if Unity is going to fix up all the broken UNET stuff, or if it's time to start abandon it and move on. The NetworkAnimator would be so nice if it worked!!!
     
  8. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Speaking of abandon....first I was using photon, then i abandoned that because it wasnt authoritative, i switched to uLink, I abandoned that since there is no support, then i switched to the new unity networking back when it first came out, abandoned that, then switched back to uLink, abandoned that again recently, now i switched back to unity networking, and also switch to WebGL from WebPlayer.

    Seems im forced to spend time re-coding all the time because the industry keeps changing the technology, and I can never release anything because of that. My fingers are swollen now from typing and I have frozen shoulder (if you havnt gotten frozen shoulder from years of daily 18 hour programming marathons, you havnt lived). This software industry will seriously kill you from the constant changes if you are not careful.
     
    nirvanajie and Ghosthowl like this.
  9. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
  10. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    There is no workaround to the NetworkAnimator bug I ended up making a animator syncing script. It goes something like this.

    Create a wrapper that controls all parameters and state enter commands.
    During initialization scan all paramaters. Then constantly serialize & sync them similar to SyncVars.
    Have a list of all state hashes (the full hash includes layer and state name). When you enter a new state you can network message send the hash and enter the state.

    This keeps all parameters synced as well as the states.

    If anybody runs into these NetworkAnimator bugs and needs to write their own let me know.
     
  11. MohammadAlizadeh

    MohammadAlizadeh

    Joined:
    Apr 16, 2015
    Posts:
    26
    Hello,
    i have the same issue
    i don't know how to set layer weight for clients and host get that message too

    this works only on clients but clients can't see local player is crouching:

    [Command]
    void CmdCrouching(float _crouchingWeight) {
    crouchWeight = _crouchingWeight;
    _animator.SetLayerWeight (1, crouchWeight);
    }
     
  12. Zullar

    Zullar

    Joined:
    May 21, 2013
    Posts:
    651
    Behind the scenes NetworkAnimator is really complex. Lets say there are 3 players
    -Server (Client1)
    -RemoteClient2
    -RemoteClient3

    What NetworkAnimator does is if it's...
    ServerOwned: Server (Client1) --> RemoteClient2 & RemoteClient3
    ClientOwned: RemoteClient2 --> Server (Client1) --> RemoteClient3

    You would need to do something similar. [Command] only sends information from Client to Server. It only...
    ServerOwned: Server (Client1) --> Server (Client1)
    ClientOwned: RemoteClient2 --> Server (Client1)

    Once the [Command] is received by the server you would need to repeat that message to clients in order for them to see it (and ideally avoid re-sending it to the owner or sending it to the server's client). There is no way to send information directly from clients to other clients, it's always 2 steps (client --> server and then repeat from server --> other clients).

    I think you are better off using MessageBase instead of [Command]'s or [ClientRPC]'s because it avoids duplication of code when doing stuff like this.
     
  13. MohammadAlizadeh

    MohammadAlizadeh

    Joined:
    Apr 16, 2015
    Posts:
    26
    i fixed it with [ClientRPC]'s
     
  14. RemDust

    RemDust

    Joined:
    Aug 28, 2015
    Posts:
    431
    "I can't decide if I should wait and see if Unity is going to fix up all the broken UNET stuff"
    That was a good one ! :D