- Home /
Performance degradation on Android and iOS switching between scenes
I have a very simple game in which the player, from the main game scene, can click a button to load an inventory scene. In this inventory scene, I have only a Scroll View that gets populated at runtime with something like the following:
foreach (var c in coins)
{
coin = Instantiate(coinTemplate);
coin.transform.SetParent(content.transform, false);
// some other stuff on this coin
}
In Editor everything works perfectly, the issue is that on Android and on iOS I have very bad performance degradation every time the user switches between the two scenes. So the first time the inventory gets loaded game performance is normal, it gets slower after 2 or 3 times and unusable after 7 o 8 times.
Could it be a garbage collection problem?
I have tried to follow suggestions from the following link, but it didn't help: https://medium.com/@lynxelia/unity-memory-management-how-to-manage-memory-and-reduce-the-time-it-takes-to-enter-play-mode-fd07b43c1daa
Answer by RaffaeleT · Jun 19, 2021 at 07:53 AM
The solution was to keep the inventory always in memory, and switch between the scenes with LoadSceneMode.Additive.
Answer by PhyrePhrost · Jun 12, 2021 at 09:14 AM
Can you send the entire method of this code and also the method that call this one? and, usually, how many items are loaded in this foreach?