- Home /
Drop on fps while disabling/enabling too many renderers at once (2D)
So I have a big 2D world, with something like 400.000 GameObjects, the character has a gameobject with a trigger collider attached to it, the collider is 30x20 units width/height. Then all the objects have a trigger collider as well, so I then use TriggerEnter2d and TriggerExit2D to enable/disable the spriterenderers of all those thousands of objects.
This makes the game run smooth (60fps), as there's only 30x20 objects being rendered at once, the problem is that when I move the 30x20 collider picks 100 Objects at once (30 enters on width, 20 enters on height, 30 exits on width, 20 exits on height) and then runs a method for disabling/enabling the renderers, that's 100 methods running at once, And the method itself has a foreach, as some objects have more than 1 child object (for example a tree has 9 sprites instead of 1). for this reason the fps drops from 60 to around 45 every time I move and makes the movement feel clunky.
What could I do to make this in a better way performance-wise? Would it be any better if I call the enable/disable renderer method as a coroutine? I've never been very good with optimization, please help me >u<