- Home /
How much do I need to optimize off-screen objects?
I'm making a basic 2D top-down space shooter. There's a map you fly around and there are lots of things that are off-screen (asteroids, enemies, bases, etc.). Is it enough to just disable the renderer for these objects while they're off-screen? Is there more I should be doing to optimize for performance?
Unless you have hundreds or thousands of objects off screen, then you might be doing early optimization unnecessarily. Have you profiled the game to decide if it's really a slowdown?
Answer by Baste · Dec 18, 2014 at 11:22 AM
Unity uses something that's called frustrum culling, which basically prevents stuff outside of the screen from being drawn. This is also included in the free version.
So disabling the renderer on objects that are outside the viewport should do exactly nothing. You can check for yourself, just put some large textures outside the screen, turn their renderer on and off, and take a look at your fps. There will probably be no difference.
Now, if you've got an entire world outside your view, you might not want to have all of it loaded at the same time. If it's just a big scene, and you're not doing crazy pathfinding algorithms every frame for every ship, you'll probably be fine keeping everything in at the same time.
If you're getting bad performance, you might want to look into some kind of object pooling system. BUT! Never do object pooling before you've actually identified that your game is running slowly, and understand why that's happening.
Answer by Qasem2014 · Dec 17, 2014 at 10:07 PM
i think you need create a prefab for them and create them in game disable the renderer not help . even disable the gameobject not help too you need create enemy and destroy them with destroy() function
WHAT ? U wana keep all objects in memory ? is that good for performance ?
No I was thinking of object pooling like @Baste says, with a simple 2D marker movement system for the objects that are not visible, which are then replaced by real objects from the pool when they are close to being in view. It depends on the target platform and also as @Baste says identifying why you game is running slowly before you do anything, inc telling someone to do what you have told them to do here. On a mobile device(or an old laptop) with many objects Instantiate and Destroy can completely kill the frame rate...
YEAH . "culling" option should be your answer . i completly forgot about it :)
Your answer
Follow this Question
Related Questions
Update Renderer Bounding Volumes - Lower Game Performance 1 Answer
Changing two different objects renderer colour 1 Answer
Make a stand alone exe file with no graphic 1 Answer
Drop on fps while disabling/enabling too many renderers at once (2D) 0 Answers
Perfermance improvement when updating hundreds of thousands particles (objects) at runtime 3 Answers