Confused about the authority

hi i have 3 question if anyone can help me understand, thx in advance

1 : why using hasAuthority is valid isnt using it on a host means its always true because the server has authority over everything, or dose the server lose authority if you assighn the connectionToClient to a non host client

2 : why not always use connection to client to check for authority since it will return the correct value regardless if you are a host or a client only

  • in other words when to use hasAuthrity and when to use connection to client

3 : if i use has authority dose it return a value based on the function i called it from, or the game object that the script is attached to it
-in other words if i use has authorit in a client function will it return diffrent value than if i use it in a server function even tho they’r both at the same script file

sorry for my bad english xD
and sorry if the questions are super basic

Hi there, good questions!

  1. By default the server has authority over everything, even if you assign the authority to a specific client connection. So yes, hasAuthority is always true on server objects.

  2. connectionToClient will help the server pick out objects assigned to specific clients. It is used to help the server differentiate between all the client objects. hasAuthority is more useful on the client side (since on the server it will be true for all server objects). You can use hasAuthority to figure out if an object belongs to the client who “owns” the current instance of the game. For example in scripts on units, you might want to check if unit’s belong to you before selecting them.

  3. hasAuthority will indeed return a different value depending on which gameObject it is attached to and in different functions depending on which instance of that gameObject it is called on. For example, instances of the players exist on each client and the server. The server is syncing much of the information between the players, but there are independent versions on each local machine. So hasAuthroity will always return true on a server function on the server. That server function won’t be called on the client instance of the player. In a client function on the client version, it will return true if it is on the player who’s client it is on. On other players on the same client it will return false.

Hope this helps, let me know if I can explain further.

thank you, that help a lot

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms