UdonSharpBehaviour throws ArgumentNullException during PrefabStage autosave when Unity pseudo-null object is serialized
tracked
ここあ こあ
Environment:
- Unity version: 2022.3.22f1
- VRChat SDK Worlds: 3.10.3
- VRChat SDK Base: 3.10.3
- UdonSharp included with SDK
- Project uses Prefab Mode / PrefabStage with UdonSharpBehaviour components
- YamaPlayer package present: net.kwxxx.yama-stream 1.5.18
Observed:
When opening or editing prefabs containing UdonSharpBehaviour components in Prefab Mode, Unity logs repeated ArgumentNullException errors from OdinSerializer UnitySerializationUtility.
Error:
ArgumentNullException: Value cannot be null.
Parameter name: unityObject
VRC.Udon.Serialization.OdinSerializer.UnitySerializationUtility.SerializeUnityObject(...)
UdonSharp.UdonSharpBehaviour.UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize()
and similarly:
UnitySerializationUtility.DeserializeUnityObject(...)
UdonSharp.UdonSharpBehaviour.UnityEngine.ISerializationCallbackReceiver.OnAfterDeserialize()
Trigger:
- Open a prefab containing UdonSharpBehaviour in Prefab Mode
- Move a child object or let PrefabStage autosave run
- Errors repeat, sometimes dozens/hundreds per save
Expected:
PrefabStage autosave should not throw if a Unity pseudo-null UdonSharpBehaviour or serialized target is encountered. It should skip invalid objects or handle UnityEngine.Object pseudo-null safely.
Additional finding:
For diagnosis only, I temporarily tested a local guard around the SDK serialization path. The test indicated that the affected object was not a normal C# null reference, but behaved as null through Unity's overloaded UnityEngine.Object null comparison. With that guard in place, the exception stopped.
I am not using this as a permanent workaround and do not intend to publish content with a modified SDK. This observation is included only to help identify the likely failure path.
Additional observation:
I have encountered this issue twice. In both cases, once the issue started occurring in the project, checking out older repository commits did not reliably make the issue disappear. This suggests that the trigger may involve Unity Library/cache/generated SDK state or some project-local serialized state, not only the currently checked out asset files.
Log In
someka
Adding a note since I encountered the same exception with a different trigger.
Symptom
For a prefab containing an UdonSharpBehaviour, after modifying the script (a class inheriting UdonSharpBehaviour) and then running "Overrides" > "Apply All" on a prefab instance already placed in the Hierarchy, I get a large number of
ArgumentNullException
errors with the same stack trace as this post.ArgumentNullException: Value cannot be null.
Parameter name: unityObject
VRC.Udon.Serialization.OdinSerializer.UnitySerializationUtility.SerializeUnityObject(...)
UdonSharp.UdonSharpBehaviour.UnityEngine.ISerializationCallbackReceiver.OnBeforeSerialize()
The Apply itself completes successfully, and I haven't observed any actual harm to runtime values or builds.
Steps to reproduce
- Remove or rename some fields on an UdonSharpBehaviour
- Select a prefab instance that includes this component and is already placed in the Hierarchy (in-scene)
- In the Inspector, run "Overrides" > "Apply All" for that component
- Numerous ArgumentNullExceptionerrors are logged to the console
How this may differ from ここあ こあ's report
According to ここあ こあ's report, the cause is attributed to a UnityObject field whose referenced target has become Unity's pseudo-null, during PrefabStage autosave / moving a child object.
In my case, I suspect it's different: modifying the script removes/renames the field itself, leaving an orphaned entry (for a field name that no longer has a corresponding definition) in the public variables table held by the in-scene instance. Re-serializing that orphaned entry during Apply then triggers the same exception.
Since the stack trace (the code path where it occurs) looks identical, there's likely a shared underlying fragility in how OdinSerializer handles the UnityObject reference list. However, the actual trigger conditions may be a different pattern, so I'm sharing this as additional context.
- Unity version: 2022.3.22f1
- VRChat SDK Worlds: 3.10.4
- VRChat SDK Base: 3.10.4
- UdonSharp included with SDK
This post was marked as
tracked