TheEvil_potato
TheEvil_potato

Reputation: 33

Unity | MissingReferenceException: The object of type 'Transform' has been destroyed but you are still trying to access it

MissingReferenceException: The object of type 'Transform' 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.Transform.get_position () (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineTransform.cs:28)

Destroy+$SpawnAfter5Seconds$1+$.MoveNext () (at Assets/Scripts/Destroy.js:22)

Any help?

Upvotes: 1

Views: 17280

Answers (2)

axwcode
axwcode

Reputation: 7824

You are tying to perform an operation on an object which is now null because it was Destroyed.

Solution

Don't Destroy it or don't try to access something that is already destroyed. You can always check like this:

if(transformReference != null)
{
    // Safe to use. 
}

Upvotes: 2

PanaitStudio
PanaitStudio

Reputation: 25

It means that the object you are trying to move, change position, etc. id destroyed. Try making a new object called like the object you used in your script. If it doesn't help, post the script in a comment. Have a great day!

Upvotes: 0

Related Questions