I’m making a 2D platformer and I was wondering what method would be effective in enhancing performance by selectively activating and deactivating gameobjects within the camera’s view and out of the camera’s view. There are 2 methods that seem viable at the moment.
- I was reading in this thread to create a giant collider around the player and activate objects that go within reach of the collider.
This would only make sense if you were activating certain components of a game object such as a script or a collider, but it wouldn’t work if the entire gameobject was inactive. If the gameobject was initially set to inactive ‘OnTriggerEnter2D’ wouldn’t fire, hence this method is effective for parts of gameobjects.
- Another method was this:
where you partition your game world into small parts and selectively activate all the objects present within that specific part of the game world. This seems like a decent strategy but incurs the overhead of creating more gameobjects in memory and probably more colliders to detect entering and exiting areas.
My ideal solution would be activating gameobjects that are initially inactive and the 2nd solution seems like the best solution so far. Would anyone have any suggestions or recommendations on any alternatives?