IsLocalPlayer should check on NetworkObjectId instead of OwnerClientId
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
hey @Dockyardb,
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?
Also, I wonder why you'd think that we should change NetworkObject. IsLocalPlayer getter to compare NetworkObjectId against NetworkManager. LocalClientId?
I think comparing OwnerClientId against NetworkManager.LocalClientId is correct.
Do you mind clarifying reproduce steps in more detail? A step by step reproduce would be great!
Thank you, Looking forward to hearing back!
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?
- Start with the tutorial
- 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.
Is there any intention to fix this issue? I would make a pull request but my push was denied...
@Dockyardb your PR wasn't denied. It's still open, and you haven't signed the CLA. Go review the PR and it tells you what to do. That said, your PR is incorrect - NetworkObjectId is a unique object id, it has no relation to LocalClientId. If this change works for you, it's purely by coincidence.
@JesseOlmer It might be true that NetworkObjectId is not the right id to use there but neither is it OwnerClientID. If i want to use a authoritive server for my movement i need to give the server ownership so the NetworkTransform is shared from the server but when you do this IsLocalPlayer returns falls on the client side since its not the owner anymore.
I know that the MR is still open but it can probably be closed since i don't want to share this much information with unity at the moment.
@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.