Megathread: Errors with prefabs and object references (EnsureRunningOnMainThread, "does not match target types", variables, etc.)

Lazlo Bonin (Lead Developer) 3 years ago updated 3 years ago 6

We're currently investigating a series of related issues with prefabs and Unity Object references.


Deserialization errors

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.

    Bolt Version:
    Unity Version:
    2018.3 Stable
    Scripting Backend:
    .NET Version (API Compatibility Level):

    Thanks for the update. The above issue describes my problem 

    Looking forward for the fix :) 


    Just wanted to mention here thankfully (after updating to the latest v1.4.1), with multiple exits/reopens/applying changes to the prefab and reopening, etc, the prefabs are finally keeping everything including their embeded flow machine too!
    Previously opening a copy of the project I lost all these references and embeded flow machines.
    To update I copied my project (thankfully I had a copy pre-losing all the references in the last Unity update), and before touching anything I downloaded>imported the update and went through the update dialog, then looking at all the prefabs everything was working.


    Indeed, updating this as everything should be fixed in v.1.4.1 stable!

    When i try and update bolt through my project, i don't get 1.4.1, i get 1.4.0f11

    The update wizard doesn't download new versions for you, it only updates to the currently imported version. Just download 1.4.1 from either the Asset Store or our Download page: http://ludiq.io/bolt/download/1.4.1