MissingReferenceException when GameObject is destroyed on Start

Eric Welwood 3 years ago updated by Lazlo Bonin (Lead Developer) 2 years ago 6

If a script destroys the current GameObject on Start, then this error is thrown from State Machine.

MissingReferenceException: The object of type 'StateMachine' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
(UnityEngine.Object uo) (at
Bolt.ValueInput.GetDefaultValue ()
Bolt.ValueInput.GetValue (Ludiq.Recursion recursion)
Bolt.XUnitValuePort.GetValue (IUnitValuePort gettable, Ludiq.Recursion recursion, System.Type type)
Bolt.MemberUnit.UpdateTarget (Ludiq.Recursion recursion)
Bolt.InvokeMember.Enter (Bolt.Flow flow)
Bolt.ControlInput.Trigger (Bolt.Flow flow)

Bolt Version:
Unity Version:
Scripting Backend:
.NET Version (API Compatibility Level):
Cannot Reproduce

Hi Eric,

I haven't been able to reproduce a "bug" version of this.

Are you sure the graphs in your state machines shouldn't actually be checking for null?

If you try to access a game object that was destroyed elsewhere, you will get this error -- that's just normal in Unity.

For example:

If you think this is a bug and the current state machine tries to keep executing after having been destroyed, please create a small test scene in which this can be reproduced.

Set a timer with the Wait unit.

Before the timer runs out, reload the scene.

When the timer runs out you'll get the error above.

That's "by design", but I'm not sure I want this feature now that I think of it.

Basically wait units will continue executing even if their owner game object is destroyed. This is useful for running code after a scene has loaded, but very confusing for these situations. Edit: This will be changed in v.1.2.4.

In the mean time, use the Null Check to be extra sure.