Closed Yoraiz0r closed 6 months ago
Although this problem seems to hint at a far bigger issue to my intuition, I've resolved it for development purposes with a temporary fix, I've locally adjusted NetworkObject.Awake
to include m_ChildNetworkBehaviours = null;
. I don't think this should be necessary but, as I don't know where the auto-initialization of this field comes from, I'll use this for now. It seems to resolve this specific issue well enough.
Although this problem seems to hint at a far bigger issue to my intuition, I've resolved it for development purposes with a temporary fix, I've locally adjusted NetworkObject.Awake to include m_ChildNetworkBehaviours = null;
I will look into this potential fix for the issue described above. (Thank you for posting your findings!)
Description
If you have a network object in a scene (a "scene" network object, not spawned by players), and you have the project setting "Editor/Enter Playmode Settings/Reload Scene" disabled, and you reload the domain (such as after changing code and triggering a recompile), the scene network object will not trigger any of its network behaviour calls (such as
OnNetworkSpawn
).This has 100% reproduction rate if you have "domain reloading" enabled, and "scene reloading" disabled.
If you also have "domain reloading" disabled, then exiting playmode, and then entering playmode a second time, will trigger the network behaviour calls properly.
I've pulled the netcode for gameobjects package locally and debugged it. The situation seems as follows: After the domain reload, at the moment of the
NetworkObject.Awake
, the memberm_ChildNetworkBehaviours
is set to a list of0
size. This is erroneous, because the list of child network behaviours should begin as null. See the code below.The list only ever fetches the proper set of behaviours if it is set to null, but it seems that somewhere, the editor gives it an instance without ever calling the
ChildNetworkBehaviours
getter.If have domain reloading disabled and enter playmode a second time, you will witness that
m_ChildNetworkBehaviours
is null this time, which is even weirder.Reproduce Steps
public override void OnNetworkSpawn() { Debug.Log("test"); }
NetworkManager
, some button to begin hosting, and a gameobject with aNetworkObject
and your networkbehaviour.test
method does not get calledActual Outcome
NetworkBehaviour calls do not get called if scene reload is disabled
Expected Outcome
NetworkBehaviour calls properly get called regardless of if scene reload is disabled
Environment
Additional Context
I'm not sure whether to put the blame on Unity's editor, or the getter property using faulty caching strategy. Additionally, my personal thought is that this collection would be better off being assigned on validate, instead of being paid its cost at runtime. Is there any reason that is not the case? Either way, this bug makes it impossible to work with NGO with domain & scene reloading both disabled for maximum editor speed.