- Home /
The object of type Sprite Renderer has been destroyed but you are still trying to access it
I got this, without noticing what I have just done. Browse the unity answer and forum, and seems nobody have ever encountered this. Or if so, they could easily fixed themself.
Anyone can spot what error caused by this in general case, please?
In general case it means that you have a
SpriteRenderer renderer = GetComponent<Spriterenderer>();
or such, a variable referencing a SpriteRenderer.
Then you do a Destroy(renderer); or Application.LoadLevel() that causes unity to destroy the renderer and/or the gameobject, but you still have a reference to it (if you used LoadLevel, then the referencing variable is static or on an object that you called DontDestroyOnLoad() on).
After the renderer is destroyed, you still try to access it in some way like renderer.sprite = somesprite
exactly lime the error says
This is basically a null reference error but Unity handles it differently for objects such as Components
Surely I have never referencing SpriteRenderer. Got no clue how this could happen .
Anyway thanks for your time explain to me. Regards,
Your answer
![](https://koobas.hobune.stream/wayback/20220612060938im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UI Source image and render order issues. 0 Answers
UI wont show up on Build? 0 Answers
how fix this problem of image ui disappearing when animated. 0 Answers
"NullReferenceException: Object reference not set to an instance of an object" with instantiate C# 1 Answer
My UI objects only show up in a wireframe mode/transparent , how to make it visible? 0 Answers