I’ve searched for hours on the internet and on the unity3d forum, a lot of thread as been created for almost the same error as mine but I still don’t know how to fix my trouble. (target platform is ios, using Unity 4.6.3f1)
here is my trouble:
in my canvas I have a simple Image with a sprite by default.
The purpose of this image is to simulate an animation by changing the image.sprite or image.overrideSprite which will be done in an IEnumerator.
The problem is that I have 1000 sprites for this animation and on my Mac mini after displaying the 200 sprites, Unity3d crash with the memory allocation error.
So far here are what I’ve seen on the internet and tried without any success:
1- Create a Sprite list using Sprite → if Sprite is made public Unity crash after putting around 300 Sprites, If Sprite is private, using Resources.LoadAll(); will quickly result to memory allocation crash
2- tried to Resources.UnloadAsset() : by putting image.sprite as parameter result in a cast error next time image.sprite is called, if I create a Sprite (Sprite mySprite; mySprite = Resources.Load(…); image.sprite = mySprite) and put this Sprite in UnloadAsset(), I’ll still have the memory crash.
3- create a prefab of my image and use Instanciate(): I used DestroyImmediate() for removing my gameobject a recreate a new one. → still have the memory crash.
my question is : in an IEnumerator, how can I change the image.sprite/image.overrideSprite using Resources.Load() without having memory leak?
I’ve also tried this without any result:
Sprite mySprite = Resources.Load();
myImage.sprite = mySprite;
mySprite = null;
could you please help me with this trouble? I have to get this works before monday:S
I really thank you in advance for your help