Search Unity

Player Authority

Discussion in 'Multiplayer' started by jethrogillgren, Apr 19, 2018.

  1. jethrogillgren

    jethrogillgren

    Joined:
    Jan 11, 2017
    Posts:
    28
    Hi All,
    I want to send a Command from a (Non-Player) object.
    If I did that I would get "Trying to send command for object without authority".

    I thought that ticking "Local Player Authority" on the NetworkIdentity would give me authority, but it seems It does not.

    Am I understanding the system wrong? Or am I doing something wrong elsewhere?
    These are scene objects, saved as prefabs and added as a Spawnable in the NetworkManager. The script has NetworkBehaviour, and it previously worked when it was used on a player object.
     
  2. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    I believe you only have authority if you spawn it yourself, otherwise you need to send commands to the server which handles scene objects or assign authority for the object with NetworkIdentity.AssignClientAuthority

    It's explained here https://docs.unity3d.com/Manual/UNetConcepts.html at the "client authority for non player objects section "
     
    jethrogillgren likes this.
  3. jethrogillgren

    jethrogillgren

    Joined:
    Jan 11, 2017
    Posts:
    28
    Thanks, that's been my workaround - assigning authority afterwards using AssignClientAuthority. But there's too many workarounds in my project now and I need to understand why the things don't work as I expected!

    So you're saying the box I select in the inspector "Local Player Authority" does not actually assign me authority - I need to have spawned it with authority, or for scene objects assign it afterwards using AssignClientAuthority?
    That seems to make no sense... what does the box do then? Why would the box say "player authority" if I have to set that myself afterwards? The NetworkTransform seems to work Client>Server with me just setting the tickbox, I don't have to assign authority a second time.

    Under the Scene Objects section it says that all scene objects will be Spawned "automatically by the NetworkManager when the server scene finishes loading".
    So I would have expected a scene Object with Local Authority to be spawned with Local player authority at that point? When the server scene finishes loading and all networked objects which were already sitting in the scene get Spawned. Why wouldn't they get spawned with authority at that point, as they are marked such!

    Thanks for any help understanding. I'm tired of working around things and not understanding - i'm sure it's causing more problems further down the line.
     
  4. lejean

    lejean

    Joined:
    Jul 4, 2013
    Posts:
    392
    I think it just means that the object is able to be controlled by clients, but you still need to assign authority to somebody before he can effectively control it, cause think about it, if you have a scene object with local player authority checked and nothing else, but you're playing with 10 people, who controls it?

    It still needs a network ID assigned.

    That's my guess at least :)
     
    jethrogillgren likes this.
  5. jethrogillgren

    jethrogillgren

    Joined:
    Jan 11, 2017
    Posts:
    28
    Thanks, that makes total sense! You're right, of course it doesn't know which client will be the owner.
    I got stuck with the names for the two concepts being basically the same.

    So, to change authority at runtime, should I be setting A) LocalPlayerAuthority and also calling B) AssignClientAuthority ? To make sure that A) clients are allowed to control it and B) an individual client is set to be the controller.

    Thank you for clearing this up for me!