- Home /
Should I pool an object that only spawn every second?
I have a nonmono enter code here
"Tile" class, which holds a reference to the tile gameObject. Basically its an infinite level. The Tile class holds alot of data, and so if I were to pool the objects, I would have to reset all of said data each time. Is it worth it to pool?
Answer by YetAnotherKen · Sep 07, 2019 at 02:26 AM
If you think you might be spawning thousands of tiles during a game then it might be easier to use Object Pooling to reduce memory usage, this is usually more relevant for mobile games. Another option is to set it to an inactive state when it is out of view of the player, this helps keep the game running smoothly, though I only use it if I plan to re-use the tile. If I was not going to ever show that tile to a player again then I would destroy it so it would get garbage collected sooner.
Thanks for answering. It is single tile path, so only about one object per second. If I disable the game object, then when I re-enable it there are multiple properties I need to reinitialize. I am trying to deter$$anonymous$$e if this re-initialization is more costly than object pooling.
Object pooling can reduce overhead in that the objects retain their settings. If the settings remain relatively constant, you can make a prefab of the object then instantiate the prefab in order to get an object created with all those property values you setup for the prefab.
If the tiles co$$anonymous$$g up are different all the time then I would just destroy the tiles behind (assu$$anonymous$$g the player never goes back to them). In this case you could still use a pool of objects to reduce spawn time for the tile, you would still be facing the overhead of altering what is on the tile, when using pooling, you don't destroy the objects, they just get set to inactive, that way you avoid the computing time needed for garbage collection.