Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Is this behaviour of IsLocalPlayer intended?

Discussion in 'Netcode for GameObjects' started by jackward84, Jul 21, 2023.

  1. jackward84

    jackward84

    Joined:
    Jan 26, 2017
    Posts:
    87
    Example of behaviour:

    • Player joins the server and has a player (network) object assigned as their player object.
    • The server calls
      NetworkObject.Despawn(destroy: false)
      , or
      NetworkObject.RemoveOwnership()
      on the network object.
    • Now, if the host checks runs the check on the object:
      networkObject.IsLocalPlayer
      returns true.

    This behaviour, in hindsight, might have been the expected behaviour. But it leads to needing a lot of extra checks over the codebase to make sure that IsLocalPlayer really means "something that belongs to the host player", whereas a despawned/non destroyed network object or an object without any specific player ownership, I would not really expect to belong to the host "player client".

    For example, I would never expect to ask "IsLocalPlayer" on a server and get a returned value of true, so it also doesn't make much sense to me that "network objects without an assigned owner are a player object of the host".

    The description of "IsLocalPlayer" doesn't make any caveat about this either.

    Code (CSharp):
    1.         /// <summary>
    2.         /// If a NetworkObject is assigned, it will return whether or not this NetworkObject
    3.         /// is the local player object.  If no NetworkObject is assigned it will always return false.
    4.         /// </summary>
    5.         public bool IsLocalPlayer { get; private set; }