so im new in unity and i am working on a 2d android game , so in this game i have 4 scenes the first one is a logo presentation that contain a raw images
the second is the menu scene , the third is for the store and the fourth is for the game and its a long scene a little bit because the game is an endless runner so i duplecate levels to get a long running trip, so to go from scene 1 to scene 2 is okay also whene i click the store button leads me to the store scene normally and also whene comback from the store scene to menu works fine but to go from the menu to the game scene the editor freeze for about 1 minute than go to the game scene and it starts by a huge lag , so i test it in my android phone and its just like in the editor exept whene i click on the play button the game quits ,im using “SceneManager.LoadScene(index)” so any help i was searching around for an answer for while now without making any progress. Im using unity 2019.4.12.
A wild guess is that you just have way too much content in Scene 4, which it why it “lags”, since the game needs time to load everything. A few suggestions would be:
- Look into Object Pooling. If the game’s a “endless runner”, then I’d have to assume that a lot of your visual content is just repeating several times and there is no need to have dozens of copies of the same GameObject in your scene if the Players can’t see more than 1 or 2 maybe at a time (as an example).
The idea is rather simple. Instead of having 10~20 (or however many GameObjects you have right now), you just have a handful that you reuse. Instead of showing a GameObject once, you will just keep showing it again and again, as long as needed. Basically reusing it, rather than having multiple copies of it.
For example - can have a look at Introduction to Object Pooling - Unity Learn or try to search for tutorials for endless runners.
- Not entirely sure if this will help or not, since I’ve not done any mobile dev myself, but another guess would be that you’re just loading way too many GameObjects or basically an entire scene. The only thing I could think of would be to either only load the first few that the Players see at the beginning and try to load the rest as they play or alternatively look into creating a loading screen, so that your “lag” is replaced with some kind of loading bar, so that Players know that the game’s still running and just loading things.