Megathread: Errors with prefabs and object references (EnsureRunningOnMainThread, "does not match target types", variables, etc.)
We're currently investigating a series of related issues with prefabs and Unity Object references.
If you're using Bolt v.1.4.1b2 or below, you'll see an error like this:
Deserialization into '...' failed. ---> System.InvalidOperationException: EnsureRunningOnMainThread can only be called from the main thread
If you're using Bolt v.1.4.1b3 or above, you'll see an error like this:
[Deserialization] Object reference at index #X does not match target type (UnityEngine.Object != ...). Defaulting to null.
Nulled out variable references
When referring to an object reference that is linked to a prefab, a variable might get cleared or nulled.
Issues with variables in nested prefabs
Defined variables were reported to get removed or cleared.
Wrong restrictions in object picker field
The object picker field may allow for scene references inside a prefab definition, or on the opposite, disallow scene references inside a prefab instance.
We're suspecting a new quirk introduced in the stable version of Unity 2018.3 to be the root cause of all of these issues.
Basically, it appears that references to objects on prefabs are getting pseudo-nulled (their native pointer is getting unlinked) when a prefab definition is changed.
A prefab definition change occurs when:
- Overrides are made on a prefab instance, then Applied to the prefab
- Changes are made directly in the prefab definition in Prefab Isolation mode
Both of these actions could trigger the errors above.
Workarounds / Fix
We're currently investigating this issue. We don't know of a reliable workaround in the mean time. It is our highest priority issue at the moment.
Customer support service by UserEcho