Open zachstronaut opened 2 months ago
The object I was re-parenting was IsSpawned == true but the re-parenting was still silently failing. It's possible the NetworkObject I was targeting as a parent was not itself IsSpawned yet and there was a race condition there?
NetworkBehaviour could have a virtual method that's like OnSceneSycned or OnPostNetworkSpawn something... it would be called after OnNetworkSpawn has completed for all scene spawned network objects.
@zachstronaut Yeah, that is a tricky one to solve for while in the middle of a scene loading event especially if you are handling the parenting within the OnNetworkSpawn method since it will be greatly dependent on both the parent and child/children being spawned before handling parenting.
A few things you could do:
NetworkSceneManager.OnLoadComplete
on the server/host side.
NetworkSceneManager.OnLoadComplete
SceneEventTypes.OnLoad
will be sent to clients
Let me know if this helps resolve your issue?
@NoelStephensUnity yes, I solved it via creating my own callback from a scene event handler sort of like your suggestion.
I think it is a bug though that re-parenting can silently fail.
And consider it a feature request for all NetworkBehaviours to have both an OnNetworkSpawn and also some sort of OnPostNetworkSpawn ... consistent with Awake()/Start() and how having those be separate allows for avoiding a certain type of race condition.
And consider it a feature request for all NetworkBehaviours to have both an OnNetworkSpawn and also some sort of OnPostNetworkSpawn ... consistent with Awake()/Start() and how having those be separate allows for avoiding a certain type of race condition.
Similar to my previous replay in your other filed issue, I am very much in alignment with:
It provides the opportunity to handle:
💯
This is a user pain area so leaving as bug but also marking it as a feature. Note for implementation: Target v2.0.0 and back port to v1.x.x
Re-parenting done during scene load doesn't sync to clients, it just silently fails. As best I can tell, there's no bool in NetworkManager that corresponds to this state. You have to subscribe to
NetworkManager.SceneManager.OnSceneEvent
yourself and implement your own bool.