question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IsLocalPlayer should check on NetworkObjectId instead of OwnerClientId

See original GitHub issue

Describe the bug When you remove the ownership of an NetworkObject. IsLocalPlayer is not true for the localPlayer but NetworkManager.Singleton.LocalClientId is still the same as before.

To Reproduce Create NetworkObject and let the server remove ownership

Actual outcome The IsLocalPlayer is not true on local player anymore.

Expected outcome The IsLocalPlayer should still be true on local player.

Environment (please complete the following information):

  • MLAPI V0.1.0

Additional context In this line OwnerClientId should be NetworkObjectId

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
Dockyardbcommented, May 18, 2021

Hello @MFatihMAR,

i hope this clarifies what i wanted to say.

if I understand this correctly, you’re trying to call NetworkObject.RemoveOwnership on your own player object on the server-side and expect it to be not owned by your player anymore, is this correct?

This is correct.

Also, I wonder why you’d think that we should change NetworkObject. IsLocalPlayer getter to compare NetworkObjectId against NetworkManager. LocalClientId?

When i call NetworkObject.RemoveOwnership to give the server ownership the NetworkManager.LocalClientId remains the same. This is not suprising because since i just changed the ownership its still the same id for the local client. The Problem is when i now call NetworkObject.IsLocalPlayer on my client it returns false which should not be right because the client is still my local Player and not the server.

Do you mind clarifying reproduce steps in more detail?

  1. Start with the tutorial
  2. Add this script to the player prefab in the NetworkManager:
public class NetworkPlayer : NetworkBehaviour
    {
        private void Start()
        {
            if (IsClient && IsLocalPlayer)
            {
                RemoveOwnershipServerRPC();
            }
        }

        private void Update()
        {
            if (IsLocalPlayer)
            {
                // Do cool stuff
            }
        }

        [ServerRpc]
        private void RemoveOwnershipServerRPC()
        {
            NetworkObject.RemoveOwnership();
        }
    }

Before i remove the ownership the NetworkObject.IsLocalPlayer is true on the client (because OwnerClientId equals NetworkManager.LocalClientId), but when i call the RPC the client loses its NetworkObject.IsLocalPlayer because it is not longer the owner of the NetworkObject. So now i can’t write code that does something on clientside when iam the localplayer.

In my opintion the NetworkObject.IsLocalPlayer check has nothing to do with OwnerClientId because it doesn’t matter who is the owner at the moment it is always that one client who started the connection, that is the local player (else you could also just change the NetworkManager.LocalClientId to something else)

I hope you can now understand why i want to change the check, if not please let me know.

0reactions
NoelStephensUnitycommented, Sep 30, 2022

@Dockyardb I am just running through the remaining open issues and wanted to try and help clarify some things as well as provide you with additional updates to server authoritative NetworkTransform.

NetworkObject.IsLocalPlayer denotes that the NetworkObject in question represents the client’s “local player”. If you remove the ownership of the NetworkObject (which is what represents the local player) then the client will still have a connection but no assigned player NetworkObject.

NetworkTransform has been updated (quite a bit in v1.0.2) where ownership no longer determines authority. So a server authoritative NetworkTransform (the default) now means it is “true server authoritative” which means:

  • Client’s still can be the owner of the NetworkObject in question
  • The authority (in this case the server) controls updates for NetworkTransform
  • The client-owner can use NetworkTransform.SetState to tell the server it would like to make adjustments to its position, rotation, and scale still.
    • You can have the server approve/monitor the changes requested from an owner client by subscribing to the NetworkTransform.OnClientRequestChange delegate handler. This way you can control whether a “owner-client requested update” is valid before applying and sending the update to non-authoritative clients.

If you run into any additional issues with this please feel free to post here and I would be happy to assist you further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question - Problem Spawning Objects, help!
for the server to spawn it. The way it's done in the tutorial is by checking whether the PlayerObject is (IsLocalPlayer) , and...
Read more >
Manual: Network Identity
This allows you to inspect the information which can be useful for investigation and debugging. The scene ID is valid in all scene...
Read more >
On netcode while running as a host does the hosting client ...
To decide if the local client is the owner of a NetworkObject, you can check the NetworkBehaviour.IsOwner property. To decide if the server...
Read more >
COMPLETE Unity Multiplayer Tutorial (Netcode for ... - YouTube
I'm your Code Monkey and here you will learn everything about Game ... Then you can add whatever Network Object to it and...
Read more >
Problem with Spawning at runtime and ...
Hi, I try to implement a jenga tower. So, I have introduced a JengaBlock prefab. I have added the Networked Object, the Tracked...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found