I’m making an iOS board game.
In this game, collectibles (I’ve got 4 different types of them) are instantiated at random positions every 4” and using my character (that moves on the board) I collect ( destroy) the collectibles.
I was having a HUGE framerate problem, caused mainly by the way I managed the board (I was checking which board tiles are empty and instantiating a collectible randomly on one of them, using GameObject.FindWithTag…). After getting lots and lots of help by the community, I corrected the way these things are managed, but I’m still having low framerate (better than before, but still unacceptable).
I just learned that this, is almost definitely caused, by the frequent instantiating and destroying of objects, which kills the iphone performance. What’s more, this is an “endless mode” type of game, where one can play for many many minutes in this same level and after say 10’ there can be 100 collectibles that have been well…collected (thus destroyed). After about a minute of playing, the game is almost frozen… Oh and of course, some sounds don’t play (because of GC I suppose?)
The board has 48 tiles and at maximum it can have about 10-15 collectibles of each type on-screen (due to the fact that what kind of collectible will be instantiated is random and is done from a built-in Array with these 4 objects).
What would be a good approach to doing what I want, without instantiating/destroying the collectibles?
I’ve thought of creating 15 collectibles of each type off camera at function Start and having them moved (instantly) at random tiles every 4’’ and being moved off camera (instantly again) whenever my character collects them, but haven’t figured out how to select a random collectible between the ones that are still off board.