- Home /
Massive lag when changing scenes on Android.
I am making an endless game in unity 2d. The screen layout resembles flappy bird, and as such has obstacles, your score, you, and your controls. The main menu is part of the same unity scene and appears when the app starts and when you die. You can buy characters, which are just sprite changes in the shop. The shop is in a separate scene. The scene change was just fine, but after adding music to both scenes, and more costumes, it takes 8 seconds to go from menu to shop. 12 seconds to go back to menu. Switching to the credits scene is instantaneous, but going back takes 6 seconds. This doesn't seem like much, but I'm sure users will find it unacceptable. How do I fix this? BTW, I posted this to the forums earlier without realizing there was an answers section.
I don't know of a magic bullet answer. How big are your music files? how many sprites are you loading in this scene? You could break out the main menu and the level into different scenes. That would split the load - including halving the music load.
I'll have to count when I get on. I know that my music files are 3-5 $$anonymous$$utes long. $$anonymous$$y game also relies alot on canvases.
Answer by Ham5andw1ch · Jul 09, 2015 at 02:43 PM
I decided to combine them all into one scene. That way, it's not having to load a scene at all. Just set the active status of a canvas. It worked well in the editor, so I'm hoping it works. Updating the app on my phone now.
Answer by RayJr · Jul 09, 2015 at 01:34 PM
Ah, ok. There are two problems. That is a really long file to load into memory on android. You should consider cutting it way down and looping it. maybe to 30 seconds or less? Also, you can get a free audio editor and lower the quality to shrink the size. You likely won't even notice the difference on a mobile device speaker. If you don't want to cut the music up, definitely make the main page a separate scene. Loading 6 - 10 minutes of music is going to kill your load time.
Also, Canvas is bad news for Mobile. I'm not sure why, but they mention it a couple of times during this live training on Mobile Development. That is probably way more work to change though. You should start by cutting down your music and/or splitting your game to two scenes and see how far that gets you. You may not need to change out the canvas at all.
I fixed it. I combined all the scenes into one and set the active statuses of canvases. Works like a charm. Also, the music I'm using doesn't loop well cut in the middle. I'm using $$anonymous$$evin $$anonymous$$acleod's ouroboros, level up, and rhinoceros.
Thanks for helping though. The unity community is so nice.
Your answer
Follow this Question
Related Questions
My rigidbody2d is passing through the side of a collider2d but it's working on the top 0 Answers
Unity 2D Game Texture Lagging!!!!,Unity 5 Texture lagging on 2D Game 0 Answers
Somes problems on my 2D space shooter game (Unity 5.5.0p4) 0 Answers
Game started lagging after adding more scenes.,Game lagging after adding many scenes. 0 Answers