Game development

Stage 2 · Lesson 2 of 7

MonoBehaviour and its lifecycle

Programming for games

A is a script you attach to a (any object in a scene). Unity calls its methods at set moments, known as the . Awake runs when it loads, then OnEnable, then Start just before its first frame.

Update runs every frame, FixedUpdate at the physics rate, and LateUpdate after all the updates. OnDestroy runs at the end. Put each job where it belongs.

Setting up the object itself goes in Awake. Setup that needs other objects goes in Start. Input and per-frame logic go in Update.

Physics forces go in FixedUpdate, and camera follow goes in LateUpdate. Getting this order right removes a whole family of bugs.

Common trapreading another object in Awake before it has set itself up, which gives references that only appear sometimes.

A question to check yourself, an AI practice session and 2 cheat sheet entries come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CourseFree
    Unity Learn: Junior Programmer Pathway

    Unity Technologies · Beginner

    Unity's official free C# pathway, with small playable projects in every unit

  • GuideFree
    Learn C#

    Microsoft · Beginner

    Microsoft's free C# lessons, for the language itself when Unity code feels unfamiliar

Practise

  • Free mentored exercises in C# and C++ to strengthen the language outside the engine

Keep handy

Also worth your time

Mark this stage as not done?