Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Networking Player having authority over nested transforms

Discussion in '5.1 Beta' started by glitchers, Jun 5, 2015.

  1. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    We are working on a game where the player controls a rigidbody with nested transforms but we have come into a few issues, most of which we have worked around.

    For example, each player can control a tank. A tank is made up of the main body of the tank and the turret on top which rotates based on player input.

    Initial we tried having each piece as a network transform with one inside the other but that didn't work as the client only could have authority over one, no matter what we tried. We found that only 1 transform can have authority per client ( source )

    We then tried to have the player object use a SyncVar to get the rotation of the turret and then each other player would update each copy to reflect that. In order to do that we needed to run a Command on our player object to send the new value to the server to pass down to the other clients but we encountered another issue. We run the command on our Player class that extends NetworkBehaviour, but we also have a NetworkTransform to sync the rigidbody position. We were getting this error.

    Code (CSharp):
    1. InvokeCommand class [NetworkTransform] doesn't match [Player])
    We then found you can only have 1 Network Behaviour per client ( source )

    Our next step was make our Player extend from NetworkTransform but even when we called the base methods on all our overidden methods (such as OnStartLocalPlayer) it didn't work. We then removed all our mono methods, such as Awake or Update just to test if that worked, and it didn't work either. We removed all our custom code and just extended NetworkTransform and it didn't work as if we just had a NetworkTransform script on our object.

    Our next idea is to not use NetworkTransform and re-implement it's syncing ourselves. Subclasses do not seem to work as expected with the Unity Networking.

    Is this the only way to do this, or are we missing something fundamental?

    Thank you for your time
     
  2. Pelican_7

    Pelican_7

    Joined:
    Nov 25, 2014
    Posts:
    190
    Hey glitchers :)

    I managed to get a similar but more simple implementation working by using [SyncVar]s and synchronising these using a [Command] (http://forum.unity3d.com/threads/mu...rms-with-local-authority.330866/#post-2144460). However, there are some things to bear in mind that aren't immediately obvious:

    - The class in which my [SyncVar]s and [Command]s were HAD to be the first component on the player prefab GameObject. I know this sounds insane but without this I got the same error as you - InvokeCommand class [First component in list] doesn't match [Player])

    - [Command]s run on the server only and as such, you must pass variables to them, i.e. don't GET them in the command as you're just getting the value as it is on the server.

    As for synchronising RigidBodys, I'd also like to know what the best way is to synchronise a rigidbody using [SyncVar]s, i.e. what values should be synced? Velocity, angularVelocity, rotation, possibly not position?

    Hope that helps.
     
    AlwaysBeCoding247 likes this.
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    The InvokeCommand error message you are seeing is a bug in the beta builds. The commands still work, just that error is printed. This bug is fixed in the 5.1 RC release. You can have multiple NetworkBehaviours on an object. The tanks sample project linked in this post does exactly what you are describing:

    http://forum.unity3d.com/threads/networking-sample-projects.325096/

    There are also some bugs with SyncVars and class hierarchies in the beta builds, those are fixed in our latest code and those fixes should be in a 5.1 patch release. Before, then it is not really possible to derived a class from NetworkTransform - but you shouldn't need to, just ignore those InvokeCommand errors until the 5.1 RC build.
     
  4. glitchers

    glitchers

    Joined:
    Apr 29, 2014
    Posts:
    64
    Thanks for the reply @seanr

    We are using the 5.1 RC release and we still get that error logging.

    Thanks for the links to the sample projects, I installed the Example Project with the 5.1RC1 installer and was confused as to where the networking samples where when they weren't included there.

    Any word on when the next RC candidate will be available, I am looking forward to these fixes