Description
Description
When I use SpawnWithOwnership() to spawn an object for a player/client directly I'd expect that OnGainedOwnership() gets called either on the target client or not at all. Instead it gets called on the server only. According to #2023 the call on the server is intended behaviour.
But as I'm still new to Netcode I was very confused and thought I did something wrong. The Ownership gets assigned as expected though, and it turns out the method is just not called on one side.
In the docs for OnGainedOwnership() it states that "Gets called when the local client gains ownership of this object"
Which is misleading if this is intended, since the sole instance that calls the method doesn't even have ownership in that moment.
The feature request #1002 also touches on this problem.
Is this intended behaviour or a bug?
Reproduce Steps
- Create a NetworkBehaviour with the OnGainedOwnership() method overridden (with a Debug.Log() e.g.)
- Spawn it from the server with SpawnWithOwnership()
- See that it the overridden method only gets called on the server, not the client
Actual Outcome
OnGainedOwnership() is only called on Server when an NetworkObject with SpawnWithOwnership() for a different client is used.
Expected Outcome
OnGainedOwnership() should be called on the client referenced by the clientID in the SpawnWithOwnership(). (+ on server side if intended)
Screenshots
--
Environment
- OS: Windows 10
- Unity Version: 2021.3.13f1
- Netcode Version: 1.2.0
Additional Context
I have attached the 3 files I created quickly to recreate the issue in an empty project.
SampleProject.zip