The Start method
- Game Development course
- Beginner
- Lesson 32/83
- 4 min
Learn when the Start method is called.
When is Start called?
The Start method is the startup method of a MonoBehaviour. When the object is active and the script is enabled, it is called right before the first frame is updated, and it runs only once.
void Start()
{
puan = 0;
Debug.Log("Hazir");
}This is why initial values are best assigned inside Start.
What running once means
The code inside Start runs only once during the game and never repeats. Repeating work belongs to the Update method. If the object or the script is disabled, Start is never called.
void Start()
{
// runs only once
aktif = true;
}So Start is reserved for setup and preparation.
Practice Set the initial value
In a class named Karakter, declare an int can field. In the Start method, assign the value 100 to can and print "Can: 100" with Debug.Log.
Starter code
using UnityEngine;
public class Karakter : MonoBehaviour
{
int can;
// Start metodunu yaz
// can degiskenine 100 degerini ata ve "Can: 100" yazdir
}Sample solution
using UnityEngine;
public class Karakter : MonoBehaviour
{
int can;
void Start()
{
can = 100;
Debug.Log("Can: 100");
}
}Expected output
Can: 100
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 When is the Start method called?
- When the script file is compiled
- Right before the first frame is updated, only once Correct answer
- Once every frame
- When the object is destroyed
Explanation: Start is called once before the first update; repeating work belongs to the Update method.
2 Define the Start method
using UnityEngine;
public class Hazirlanma : MonoBehaviour
{
void ____()
{
Debug.Log("Hazir");
}
}
using UnityEngine;
public class Hazirlanma : MonoBehaviour
{
void Start()
{
Debug.Log("Hazir");
}
}
Explanation: The method signature is void Start(), and Unity calls it once before the first update.
3 Rules of Start
| Term | Meaning |
|---|---|
void Start() |
Called only once |
İlk güncelleme |
Comes right after Start |
Devre dışı script |
Never calls Start |
Başlangıç değerleri |
Assigned inside Start |