You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Normally when using a GO/NI/NB syncvar it will check the netid field first and get the object from the spawned dictionary, it will then set the real field and return the value. There seems to be a bug where if you use that field inside a class/struct before it has been set by either OnDeserialize or another method using it then it will stay null
This seems like a minor issue in Mirror since it will use the real field and not cause any errors. It will mostly cause timing issues where the GO/NI/NB field will stay null for longer than it needs to
[IMPORTANT] How can we reproduce the issue, step by step:
something like this should replicate it:
NB1 has field targeting NI2
Spawn NI1 and NI2 on server
Send NI1 to client
NB1 will store netid of NI2, but field will be null
Send NI2 to client
expected: using NB1 field will get the NI2 object from spawned dictionary
bug: using NB1 field will stay null when called inside class/struct constructor
Additional context
This should be the code in Mirror:
Tracking the code back, it seems like the ctor check is from UNET with no explanation.
After some testing it seems that setting default values for syncvar will cause errors when using the setter in a NetworkBehaviour constructor. So it seems like the check if only there to avoid it for NetworkBehaviour (and maybe other unity types).
This fix would be something like this, where you only skip the constructor for unity types: MirageNet/Mirage@2f5db3d
The text was updated successfully, but these errors were encountered:
Describe the bug
Normally when using a GO/NI/NB syncvar it will check the netid field first and get the object from the
spawned
dictionary, it will then set the real field and return the value. There seems to be a bug where if you use that field inside a class/struct before it has been set by either OnDeserialize or another method using it then it will stay nullThis seems like a minor issue in Mirror since it will use the real field and not cause any errors. It will mostly cause timing issues where the GO/NI/NB field will stay null for longer than it needs to
[IMPORTANT] How can we reproduce the issue, step by step:
something like this should replicate it:
spawned
dictionaryAdditional context
This should be the code in Mirror:
Mirror/Assets/Mirror/Editor/Weaver/Processors/SyncVarAttributeAccessReplacer.cs
Lines 135 to 168 in f2291fc
Tracking the code back, it seems like the
ctor
check is from UNET with no explanation.After some testing it seems that setting default values for syncvar will cause errors when using the setter in a NetworkBehaviour constructor. So it seems like the check if only there to avoid it for NetworkBehaviour (and maybe other unity types).
This fix would be something like this, where you only skip the constructor for unity types:
MirageNet/Mirage@2f5db3d
The text was updated successfully, but these errors were encountered: