- Home /
Reduce Draw Call for Sprite
I am working on side scrolling game so for that I want to define strategy for game objects.
I want to reduce draw call for game objects that are not in camera visibility either they are gone or not get turn to come in focus.
I have some working experience with AndEnginge in which I handle this situation in following manner.
public void enable() {
setVisible(true);
setIgnoreUpdate(false);
terrainBody.setActive(true);
}
public void disable() {
setVisible(false);
setIgnoreUpdate(true);
terrainBody.setActive(false);
}
I am pretty new to unity 2d game development so I want suggestion in this to improve performance of my game.
Also provide guidance for 3d objects if they come in same situation.
Like @CodinRonin said the camera won't create a draw call if the sprite is not on camera however if the sprite has scripts with update functions then these will still be called every frame. So if you are doing a lot in update on a lot of sprites you may want to iterate through your list of sprites and disable them with someGameObject.SetActive(false) if they are a distance (up/down or right/left) from the camera.
Answer by CodeElemental · Mar 18, 2014 at 08:57 AM
Unity cameras support what you want out-of-the box . It is called Frustum culling. (Objects that are not visible by the camera are not rendered = no draw calls)
Find out more in the documentation for camera . Look for the clip panes section.
As per my understanding, things which are in camera visibility are rendered. We have to set camera near and far clipping for performance benefit. Am right in this? There is no 2d and 3d different in this.
Yes , the things displayed on the camera are rendered. You can specify which camera renders which game objects by specifying a layer to the gameobjects and a layermask to the camera's cullmask.
Additionally the near/far clip plane can restrict displaying/rendering also ( things "in front" of near plane , and the ones "behind" far plane are not rendered.
Also , you can watch this unity official tutorial on cameras. It's pretty informative.
Thanks for all these replies. First I will look at them and reply back.
Your answer
Follow this Question
Related Questions
Atlas size based on sprite 0 Answers
Sprite Rendering Cost Calculation 1 Answer
Jelly Object for 2D Game 2 Answers
Strachable Object Creation 0 Answers
Terrain generation 0 Answers