Calls to `ChangeOwnership(NetworkManager.ServerClientId)` and `RemoveOwnership()` doesn't have same effect
See original GitHub issueDescription
While working on #2507, I remarked that calling serverObject.ChangeOwnership(NetworkManager.ServerClientId)
doesn’t have the same effect as serverObject.RemoveOwnership()
. Moreover, some automated tests use the first one, others the second.
The difference is subtil, but server side, when removing the ownership, the object entry is deleted in NetworkSpawnManager.OwnershipToObjectsTable
, while giving ownership back to the server keeps it.
Since the ownership is given back to the server in both case, I think we should let the entry in the table. The entry should be deleted only on despawn.
https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/a418eabe59ed5f5e918d1756ee051436d2819828/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs#L197 VS https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/blob/a418eabe59ed5f5e918d1756ee051436d2819828/com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs#L259
Shouldn’t RemoveOwnership()
just calls ChangeOwnership(NetworkManager.ServerClientId)
instead of having a “copy/paste but not identical” implementation?
If there is a difference made on purpose between those two calls, documentation needs to be updated to explain it.
Environment
- OS: Windows 11
- Unity Version: 2020.3.40f1 (the automated testing project of this repo)
- Netcode Version: develop
- Netcode Commit: https://github.com/Unity-Technologies/com.unity.netcode.gameobjects/commit/449bf94436ec74956fed1ac96729c55983d798a6
Issue Analytics
- State:
- Created 5 months ago
- Comments:5 (5 by maintainers)
Top GitHub Comments
@PitouGames This issue is resolved in PR #2618 and will be included in the next patch update. 👍
@NoelStephensUnity Thank you for the very detailed answer, and sorry for the delay of my response.
Concerning the automated tests, I want to highlight that you can replace RemoveOwnership with:
and no test fails, showing that this intentionnal behaviour difference isn’t properly tested. That’s the main reason I have created this issue, I couldn’t know if the difference was intentionnal or not (lack of tests and documentation).
For all the others thing we spooted along the path, it shouldn’t cause any trouble as long as the dev don’t mess up with the two functions as I did for testing. But it’s good to know it’s there 😉