Search Unity

Attach networked players to 'vehicle' problem

Discussion in 'Multiplayer' started by Davedub, May 21, 2017.

  1. Davedub

    Davedub

    Joined:
    Mar 30, 2016
    Posts:
    22
    Hi All,

    I'm working on a shared VR experience using Unity's NetworkManager. Once all the players have joined the network, I want them to all be attached to a single GameObject that I can then animate. The idea is that the host will control the animation and so be able to give the entire group a tour of the virtual space.

    I have been trying to achieve this but with no success. My basic strategy has been to create a GameObject and parent the Main Camera to it in the editor. Then, during the OnServerAddPlayer function I parent the player prefabs to the group GameObject. This seems like a reasonable approach to me, but does not seem to work (it works on the host, but not on the clients where the player prefabs do not show up and the camera remains static when the GameObject is animated).

    This sort of functionality must be easily available for situations like when all players enter a vehicle that is controlled by one player. I can only guess my strategy is wrong, or I am overlooking something.

    ~ What would be the best strategy for achieving my desired functionality?

    Many thanks in advance,

    - DaveDub
     
  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    Small tip about unet that I think is giving you problems. There's a number of functions like OnServer_____, OnClient_____, etc. anytime you see "Server" that is typically only a function that is called on the server/host player's machine. The "Client" functions are called on the non-host players' machines. Makes sense?

    so in other words, if you're only parenting in a server function, then only the host player would observe this. I recommend moving your code to OnStartLocalPlayer - this function should get called for everyone, including the host
     
  3. Davedub

    Davedub

    Joined:
    Mar 30, 2016
    Posts:
    22
    Thanks for the heads up. I'm still stuck on this, but am now focusing on the animation side of things, as I have debugged to the extent that I now see the problem lies in animation over the network. I'm now trying to animate the GameObject serverside via the NetworkAnimator - I'll worry about the attached cameras later. But no matter what I try, the GameObject just will not move on the client.

    I've tried using Triggers (fail, seems to be a long standing bug as described here: https://forum.unity3d.com/threads/animator-settrigger-networkanimator-settrigger-bug.370984/)

    I've then tried to change state on the animator by using a simple bool change - again, works on the host, nothing moves on the client.

    So I've now made a simple demo project to try and nail down exactly where I'm going wrong.
     
  4. aeclubwoi

    aeclubwoi

    Joined:
    May 12, 2017
    Posts:
    8