Hi
Apologies for this wall of text but I have been on this issue for about 10 days now ![]()
I have a menu where the player can choose one of various levels to play, then when they get game over or complete it, they can return to this menu to select and play a different one.
In the editor on the PC, the menu and all the levels work 100% fine, with no error messages in the console.
And when testing on an Android device, they all work fine except for one weird exceptionâŚ
There is one specific level that makes another specific level glitch out with scrambled/missing sprites if you go from it to the other (using the menu in-between). These scenes are both < 1MB.
So both these levels play fine, just like all the others, in any circumstance other than if you play them one after the other. And they are far from the largest in the game (largest scene is 10mb).
The visual bug/glitch is that some of the larger sprites (2048) are missing, and some are scrambled into grey lines/dots.
I have seen this once before and after assigning some items in the inspector that I forgot, it went away so I figured it was a null reference exception.
I am not carrying anything between the two scenes like with DontDestroyOnLoad or anything.
But I am using PlayerPrefs to call some data between scenes - Scores, visual customization of items etc.
What I initially tried:
-
A GUI console on the device for a null reference check (in case it wasnât showing in the editor but was on device).
-
Deleting both scenes after copying/pasting all their objects into fresh ones.
-
Deleting/rebuilding the library/re-importing the project.
-
Copying/pasting the images into ânew/freshâ PNGs and bringing them into the project and swapping them - In case they were corrupted or something.
None of that worked.
Then someone on Reddit said it sounds like I might be hitting Unityâs memory limit for images as they had seen similar when working with 60 1024 sprites, so I tried:
-
Temporarily reducing the problem sprites max size to 1024 from 2048 and the issue stopped happening! But I really could do with 2048 and seeing as they are not an issue anywhere else in the project I wanted to carry on trying to fix it properly.
-
So I returned the max size to 2048, and implemented a scene transition system using Resources.UnloadUnusedAssets() - Without using LoadScene.Async to keep memory use down as much as possible.
-
Staggered enabling of game objects at start of scene.
None of that worked.
Then I finally thought I got somewhere when I discovered:
- If I swap the problem (1.6MB) 2048 sprites, for different (700KB) 2048 sprites, the problem stopped.
- So I thought it must be down to the file size, but then while experimenting further, I discovered that 200KB 2048 sprites using the same main colours (snow colours like white/grey/blue) as the 1.6MB 2048 sprites, they STILL cause the issue. So it appeared the colours themselves were causing it. The working 700KB 2048 sprites were mostly greens.
- So then I re-coloured the 200KB 2048 snow coloured sprites to blue to test, and they work FINE. I really thought I had cracked it here and just needed to tweak the colours due to some weird colour related bug.
- But then after doing so and the 2048 sprites in question were no longer glitching, the glitch passed on to the only other 2048 sprite in the scene (an interactable game object) which is not snow coloured at all (bright red) - Itâs never done it on that one before. So its almost as if the glitch works its way through the sprites in the scene until it hits one it can mess with.
I REALLY appreciate any help, advice or suggestions on this! If it comes to it, Iâll have to admit defeat and keep the max size of the snow coloured sprites at 1024 but that really makes me feel uneasy as I worry the problem will surface again down the line.
Thank you so much!