- Home /
Unity "Cleaning up leaked objects" on save scene
Hello,
I have an editor script which creates a Texture2D:
public class MyDataClass : MonoBehaviour // attached to a game object from the inspector
{
Texture2D myTex2D;
}
public class MyEditorScriptClass
{
GameObject goWithDataComponent; // set from inspector
public void init()
{
//create texture
myTex2D = new Texture2D(640, 480, TextureFormat.BGRA32, false);
myTex2D.wrapMode = TextureWrapMode.Clamp;
myTex2D.Apply();
myTex2D.hideFlags = HideFlags.HideAndDontSave;
// ...
}
}
That texture is then applied to a Projector:
gameObject.GetComponent<Projector>().material.SetTexture(myTex2D);
This works great, it does exactly what I want it to do...until I save. Now this Texture does not need to be saved at all, it's created every time the editor script is initialized. The problem arises when I try to save the scene, Unity destroys my texture and throws this message:
Cleaning up leaked objects in scene since no game object, component or manager is referencing them. Texture2D has been leaked x times.
Now this just ain't right. The Texture belongs to a component which is attached to a GameObject in the scene, furthermore, the Projector component is referencing the texture.
What is Unity on about? How do I correct this?
Any help would be appreciated, thanks!
I'm getting the exact same problem with textures being deleted when saving the scene. I presume you fixed this, can you say how you did it?
I actually did not fix this, this project was made to be used in a research study... we changed the study to not involve saving the scene. A solution might be to ins$$anonymous$$d of creating a texture from script, create a dummy texture asset and reference it from your script.
Sorry couldn't be more helpful, interested to hear your solution.
Your answer
Follow this Question
Related Questions
align object forward with pipe 0 Answers
How to make dynamically texturable object model? 0 Answers
EncodeToPNG() causes loss of image detail: How to avoid this? 2 Answers
Counting active objects in a list 3 Answers