Tutorial 5: Scene Efficiency Volume 1
-
Author: Brian A. Ree
1: Introduction and Tutorial Goals
Hey there, this is a short tutorial on some of the basic steps you can take to increase the efficiency of the Scenes in your 3d game.
We're not going to cover some of the more advanced physics level, layers, rigid bodies, static colliders, and ray casting but we will cover a few
of the basics that you should know.
2: Getting Setup, Dive In
Grab the starting project above and fire up your Unity software. Open the project and we'll go over the changes we've made to increase the efficiency
of our simple Scene. Let's look at our 'Directional Light' Game Object in the Hierarchy window. Select it and check the static checkbox next to the
object label in the Inspector window. Because we're not using any sort of dynamic lighting, and because the directional light applies its light to the
entire scene regardless of its position we can make it a static object. This will remove it from certain scene calculations because Unity now knows that
it won't be moving around. Next up expand the light component of the 'Directional Light' Game Object and find the 'Mode' property. Alter the property so
that 'Baked' is selected. This is a hit or miss efficiency move. Depending on the needs of your game and the look you're trying to get. Selecting baked lighting
means that lighting calculations are predetermined and this improves the efficiency of the Unity engine as it does not have to calculate lighting in real time.
However the down side is that certain real time lighting effects will no longer work. See the screen shots below to review the changes.
Some Game Objects won't be moving so we can set them to static.
3: Adding Some Scripts
If your game won't suffer from no dynamic lighting try baked lighting to increase efficiency.
You can turn the lighting in your Scene window on and off by toggling this control. Baked in lighting will require a run of the scene to update.
Next up let's look at the 'Ground' Game Object. Since it will be stationary when the scene is running we can also set this to static in the same way we adjusted
the 'Directional Light' Game Object above. Take a look at our the two Game Objects that hold our script Components. These objects can also be set to static and
since they'll only be used to house our scripts we know they won't interact with any ray casting done in a game so change their layer to 'Ignore Raycast' as depicted below.
Game Objects that house only scripts can be set to static and also removed from consideration when casting rays.
Apply the same change to our other script holding Game Object.
One other object to take into consideration is our obstacles. There are a lot of them to change but if you select the parent Game Object from the Hierarchy
window and set it to static you'll be prompted by Unity to apply those changes to all the child Game Objects that belong to the parent, thank goodness.
That saves us quite a bit of work. This is why it'll save you time in the long run to organize your objects properly. Click yes and apply the changes to all
the children of the obstacles parent.
Setting the static property on all the children of a parent in one shot!
Well that's all we'll cover in this little tutorial but I think you can see how useful even this lit bit of information is. I wouldn't be too worried about making these
adjustment during the heavy development phases of your scene because you'll most likely be focusing on more game centric tasks. I would, however, recommend taking the time
to review and adjust the settings of the object in your scene once things get to a stable state, you can certainly make an impact in your game's performance with the adjustments
outlined here.