1
votes

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?

3
You're destroying the object reference , rather than the instantiated one. Instantiate a variable to hold the object and destroy that instead. - fantasitcalbeastly

3 Answers

1
votes

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. 
}
0
votes

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!

-2
votes
void FixedUpdate()
{
    Vector3 targetCamePos = target.position + offset;
    if (targetCamePos != null)
    {
        transform.position = Vector3.Lerp(transform.position, targetCamePos, smoothing * Time.deltaTime);
        if (transform.position.y < lowY)
        {
            transform.position = new Vector3(transform.position.x, lowY, 
transform.position.z);

            //if our character fallow the x/z not y
        }
    }  
}