Lightmap baking
- Game Development course
- Intermediate
- Lesson 11/83
- 4 min
Learn the lightmap baking process and the Static flag.
The Static flag
To bake a lightmap, objects must be marked as Static. A static object does not move during the game; Unity can precompute the light and shadows of such objects. The marking is done with the Static checkbox in the Inspector or from code.
gameObject.isStatic = true;
// object is now StaticObjects that move are not made static.
The bake process
The bake process starts with the Generate Lighting button in the Lighting window. Unity computes the light and shadows of static objects and writes them to lightmap files. Depending on the size of the scene, this can take some time.
// Window > Rendering > Lighting
// Generate Lighting > Lightmap filesWhen the bake is done, the light in the scene stays fixed for the whole game.
Practice Count the bake step
In a class named BakeAdimi, define a string islem field with the value "Bake" and an int adim field with the value 1. In the Start method, increase the adim value by one and print the pieces "Islem: ", islem, " Adim: " and adim joined together with Debug.Log.
Starter code
using UnityEngine;
public class BakeAdimi : MonoBehaviour
{
// string islem alanini "Bake" degeriyle tanimla
// int adim alanini 1 degeriyle tanimla
void Start()
{
// adim degerini bir artir
// "Islem: " + islem + " Adim: " + adim biciminde yazdir
}
}Sample solution
using UnityEngine;
public class BakeAdimi : MonoBehaviour
{
string islem = "Bake";
int adim = 1;
void Start()
{
adim++;
Debug.Log("Islem: " + islem + " Adim: " + adim);
}
}Expected output
Islem: Bake Adim: 2
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which statement is true for an object that does not move in the game and whose light should be precomputed?
- It is marked as Static and baked light is used Correct answer
- Its shadows are set to None
- Its light type is set to Spot
- Realtime light is used and the object stays movable
Explanation: Static objects do not move during the game, so their light can be baked in advance.
2 Make the object static
gameObject.____ = true;
gameObject.isStatic = true;
Explanation: The static state of a GameObject is set in Unity with the isStatic property.
3 Bake steps
| Term | Meaning |
|---|---|
Static |
Object that does not move in game |
Generate Lighting |
The button that starts the bake |
Bake |
The precomputing of the light |
Lightmap dosyaları |
The files produced by the bake |