Search Unity

Errors thrown when using NetworkServer.ReplacePlayerForConnection()

Discussion in 'Multiplayer' started by jfjordanfarr, Jul 27, 2015.

  1. jfjordanfarr

    jfjordanfarr

    Joined:
    Jul 2, 2015
    Posts:
    7
    Hi! I'm working on a project right now that gives 2D players the ability to take control of a vehicle. In a related forum post (http://forum.unity3d.com/threads/question-about-local-authority.333846/), I found that NetworkServer.ReplacePlayerForConnection() could be a viable way to give players authority over a vehicle object. I made a hasty implementation of this and soon realized that I needed my original player to retain authority as well - their ability to send commands related to their health would be lost by simply switching the player object for the connection to the vehicle!

    Today I've taken a second crack at the problem. I made a second "dummy" player (with its own playerControllerId) that exists on each client. This "dummy player" is a prefab carrying a network identity and no render component. I then made it so that NetworkServer.ReplacePlayerForConnection() replaces the authority on the dummy player's player controller over to the vehicle when the "real" player enters the vehicle, and leaving a vehicle gives authority back to the "dummy player". I'm getting a strange error thrown with this implementation:

    The error above runs as soon as a client player enters a vehicle.
    If the player exits the vehicle this next error is thrown:

    If a player gets in the vehicle a second time, the error above is thrown every frame. A related RPC (which tells the "real player" object to lock their movement) is running at the same rate, over and over. Any ideas as to what's going on here?
     
    Last edited: Jul 27, 2015
  2. jfjordanfarr

    jfjordanfarr

    Joined:
    Jul 2, 2015
    Posts:
    7
    A little more information: It looks like I have a warning showing up when I spawn the dummy player about a "Duplicate Observer". This warning comes back up any time I get in or out of the vehicle. Another warning appears just after saying that the "playerControllerId is higher than expected" at a value of 1. I tried changing that to 4, and the error still shows up. I know that the dummy player is spawned through a command on the real player, and I opted not to use ClientScene.AddPlayer() as I wanted a different player object for the dummy. Is that part of my trouble?
     
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
  4. jfjordanfarr

    jfjordanfarr

    Joined:
    Jul 2, 2015
    Posts:
    7
    Thanks for the quick reply!

    Taking a read through that forum link and through the beta release notes (http://unity3d.com/unity/beta/unity5.2.0b1), I saw part of a bullet point that still left me confused:

    Does this mean that whole clients only have authority on one object, or player controllers only have authority on one object? If a whole client only gets authority on one object, isn't this "dummy fix" still null and void? Do I really have to route the original player's health and commands through the vehicle?
    Edit: Or did that mean that an object can't have multiple client owners, but clients can own more than one object (so long as it is not already owned by another client)?
     
    Last edited: Jul 28, 2015
  5. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    right.. "an object can't have multiple client owners, but clients can own more than one object"