0

I'm still learning Unity. I have quite a few objects and scripts in the scene and they interact with each other. I'm getting "MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it." error every time I stop playing. I think it's because when I exit play mode, Unity destroys everything and when the object has OnDestroy() method and interacts with another object, but the object is already destroyed, this happens. It does not effect my project running, should I worry about this error? Is there a way to avoid this? Or I have to check if an object is null every time a script interact with another object?

3
  • As you pointed out, currently it doesn't affect your game. However, it seems like you are not sure where this is coming from and therefore, if something similar happens during your game, it would indeed have effect. Therefore, I suggest you find and solve the warning. You should be able to easily locate where in your code you are accessing null by debugging. Commented Apr 3, 2024 at 6:31
  • in general you should avoid any exceptions yes. Commented Apr 3, 2024 at 15:52
  • @anjelomerte I can check where this error is coming from and each time it is from a different source, I assume it's because the order unit destroys everything is random so each time there is a different script(s) giving me this error? Is there way I can tell unity to destory objects in what order? Or maybe I can set up a script to destroy everything in the order I want when player quit? Would this be a viable solution? Commented Apr 3, 2024 at 16:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.