Search Unity

Problem with Setting ClientAuthority if client is host

Discussion in 'Multiplayer' started by Mariochi, Nov 2, 2018.

  1. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    18
    Ok, I did not found anything about this on the forum so I'm asking:

    I'm trying to spawn a player model and give its control to the local player.
    But it's not working.

    https://pastebin.com/vGcqz0RK
     
  2. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    18
    Just for additional info:
    The soldier spawn on the scene, on the correct position, but the host player don't get it's authority.
     
  3. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    If the client is the server (host), you just spawn without assigning client authority.
     
  4. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    18
    Did not work. It just changed the hasAuthority "no".
     
  5. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    That doesn't make any sense. The server or one of the clients will report that hasAuthority is true, and if you're not assigning it to a client then the server has authority. Are you checking for authority in somewhere like Awake which is called on the server before the object is even spawned or something?
     
  6. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    18
    Well, I was checking isLocalPlayer for command inputs and stuff.
    hasAuthority only works if the connection I see has authority over the object?
     
  7. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    isLocalPlayer is only used on the special Player GameObject that the network manager creates for clients upon connection, or hosts when they start. Other objects spawned by the server will always have isLocalPlayer set to false.

    hasAuthority should be true on the client which the server assigned authority over the object. If the server doesn't assign authority to a client then hasAuthority should be true on the server. I don't see from your code you linked where you are checking for authority, so not sure where you are hitting your issue. For example, if you are checking hasAuthority in the object's Awake method, that would be called on the server before the object has even been spawned, so isn't the place to check it.
     
    Last edited: Nov 7, 2018
  8. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    18
    I feel dumb right now. I spend days trying to find the problem, and it's something that simple.
    Thank you so much