Search Unity

  1. Check out the Unite LA keynote for updates on the Visual Effect Editor, the FPS Sample, ECS, Unity for Film and more! Watch it now!
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Unity Multiplayer Problem with Setting ClientAuthority if client is host

Discussion in 'Connected Games' started by Mariochi, Nov 2, 2018.

  1. Mariochi

    Mariochi

    Joined:
    Nov 17, 2016
    Posts:
    17
    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:
    17
    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:
    3,817
    If the client is the server (host), you just spawn without assigning client authority.
     
  4. Mariochi

    Mariochi

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

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    3,817
    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:
    17
    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:
    3,817
    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:
    17
    I feel dumb right now. I spend days trying to find the problem, and it's something that simple.
    Thank you so much