- Home /
Does destroying a Sprite also destroy it's texture?
Does destroying a Sprite also destroy it's texture and free it from memory? Or would I need to destroy the texture as well?
Texture2D texture = new Texture2D(width, height, TextureFormat.RGBA32, mipChain: false, linear: true);
Sprite mySprite = Sprite.Create(texture, new Rect(0f, 0f, 500f, 500f), new Vector2(0.5f, 0.5f));
Destroy(mySprite.texture); // is this needed?
Destroy(mySprite);
Answer by xibanya · May 20, 2021 at 04:04 AM
destroying a sprite does not also destroy its texture; a texture is an asset-type object whereas a sprite renderer technically only exists at runtime. Be aware that if you destroy a texture you'll also destroy the asset itself. If you're very concerned with memory, try running Resources.UnloadUnusedAssets instead (but I doubt a sprite texture is going to be much of a concern.)
Your answer
Follow this Question
Related Questions
How do you crop a Texture2d 1 Answer
Unity UpdateExternalTexture from MovieTexture windows crash 0 Answers
2D sprite renders a small part of another one with "Sprite Mode : Multiple" 0 Answers
Create sprite or texture from list of Vector2 1 Answer
Destroying a square of sprites at specific coordinates 0 Answers