Bird
Raised Fist0
Unityframework~20 mins

MonoBehaviour lifecycle in Unity - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
MonoBehaviour Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output order of these MonoBehaviour methods?

Consider a Unity script attached to an active GameObject. Which sequence of method calls will Unity invoke first when the scene starts?

Unity
using UnityEngine;

public class TestLifecycle : MonoBehaviour
{
    void Awake() { Debug.Log("Awake"); }
    void Start() { Debug.Log("Start"); }
    void OnEnable() { Debug.Log("OnEnable"); }
}
AStart, Awake, OnEnable
BOnEnable, Awake, Start
CAwake, OnEnable, Start
DAwake, Start, OnEnable
Attempts:
2 left
💡 Hint

Remember that Awake is called before OnEnable, and Start is called after both.

❓ Predict Output
intermediate
2:00remaining
What happens if you disable a GameObject during Update?

Given this script, what will be the output when the GameObject is active and Update disables it?

Unity
using UnityEngine;

public class DisableInUpdate : MonoBehaviour
{
    void Update()
    {
        Debug.Log("Update called");
        gameObject.SetActive(false);
    }

    void OnDisable()
    {
        Debug.Log("OnDisable called");
    }
}
AOnly OnDisable called
BUpdate called\nOnDisable called
COnly Update called
DOnDisable called\nUpdate called
Attempts:
2 left
💡 Hint

Think about the order of method calls within the same frame.

🔧 Debug
advanced
2:00remaining
Why does Start not get called when re-enabling a previously active GameObject?

Look at this script attached to a GameObject that starts active (so Start has already been called), is then disabled, and re-enabled at runtime. Why does Start not print "Start called" again?

Unity
using UnityEngine;

public class StartTest : MonoBehaviour
{
    void Start()
    {
        Debug.Log("Start called");
    }
}

// Elsewhere in code:
// gameObject.SetActive(false);
// gameObject.SetActive(true);
AStart is only called once when the script instance is first enabled, not every time the GameObject is enabled.
BStart is called only if Awake is called first, which is missing here.
CStart is called only if OnEnable is overridden in the script.
DStart is called only if the GameObject is enabled in the editor before play.
Attempts:
2 left
💡 Hint

Think about when Start is triggered in the lifecycle.

📝 Syntax
advanced
2:00remaining
Which method signature is correct for OnDestroy in MonoBehaviour?

Choose the correct method signature for the OnDestroy callback in a MonoBehaviour script.

Avoid OnDestroy()
Bvoid OnDestroy(bool isPermanent)
Cpublic void OnDestroy()
Dvoid OnDestroy(GameObject obj)
Attempts:
2 left
💡 Hint

Check the Unity documentation for OnDestroy method signature.

🚀 Application
expert
2:00remaining
How many times is FixedUpdate called per second if Time.fixedDeltaTime = 0.02?

In Unity, if Time.fixedDeltaTime is set to 0.02 seconds, how many times will FixedUpdate be called per second?

A20 times
BDepends on frame rate
C100 times
D50 times
Attempts:
2 left
💡 Hint

Think about how fixedDeltaTime relates to FixedUpdate frequency.

Practice

(1/5)
1. Which MonoBehaviour method is called exactly once when the script instance is being loaded, before any Start methods?
easy
A. FixedUpdate()
B. Update()
C. Awake()
D. OnDestroy()

Solution

  1. Step 1: Understand MonoBehaviour initialization order

    Awake() is called once when the script instance is loaded, before Start().
  2. Step 2: Differentiate from other lifecycle methods

    Update() and FixedUpdate() run repeatedly, and OnDestroy() runs when the object is destroyed.
  3. Final Answer:

    Awake() -> Option C
  4. Quick Check:

    Awake runs once at load = Awake() [OK]
Hint: Awake runs once at load, before Start [OK]
Common Mistakes:
  • Confusing Awake with Start
  • Thinking Update runs once
  • Mixing OnDestroy timing
2. Which of the following is the correct syntax to declare the Update method in a MonoBehaviour script?
easy
A. void Update() {}
B. public void Update() {}
C. private Update() {}
D. Update void() {}

Solution

  1. Step 1: Recall method declaration rules in C# for Unity

    MonoBehaviour lifecycle methods like Update are usually declared as void Update() without access modifiers.
  2. Step 2: Check each option's syntax

    void Update() {} is correct syntax. public void Update() {} is valid C# but Unity recommends no access modifier. private Update() {} is missing return type. Update void() {} has wrong order.
  3. Final Answer:

    void Update() {} -> Option A
  4. Quick Check:

    Correct method syntax = void Update() {} [OK]
Hint: Update method is always void Update() {} [OK]
Common Mistakes:
  • Using wrong order of return type and name
  • Omitting void return type
  • Adding private keyword incorrectly
3. What will be the output of the following code attached to a GameObject?
using UnityEngine;

public class TestLifecycle : MonoBehaviour {
    void Awake() {
        Debug.Log("Awake called");
    }
    void Start() {
        Debug.Log("Start called");
    }
    void Update() {
        Debug.Log("Update called");
        enabled = false;
    }
}
Assuming the game runs for one frame, what messages appear in the Console?
medium
A. ["Awake called", "Start called", "Update called"]
B. ["Awake called", "Start called"]
C. ["Start called", "Update called"]
D. ["Awake called", "Update called"]

Solution

  1. Step 1: Understand method call order on first frame

    On first frame, Awake() runs once at load, then Start() runs before first Update, then Update() runs.
  2. Step 2: Analyze Update disabling script

    The Update() method disables the script after logging, so it runs once this frame only.
  3. Final Answer:

    ["Awake called", "Start called", "Update called"] -> Option A
  4. Quick Check:

    Awake, Start, Update run once first frame [OK]
Hint: Awake and Start run before first Update [OK]
Common Mistakes:
  • Thinking Update disables before logging
  • Missing Awake call
  • Assuming Update runs multiple times first frame
4. Identify the error in this MonoBehaviour script:
using UnityEngine;

public class Example : MonoBehaviour {
    void Start() {
        Debug.Log("Start called");
    }

    void Update() {
        Debug.Log("Update called");
    }

    void OnDestroy() {
        Debug.Log("Destroying object");
    }

    void awake() {
        Debug.Log("Awake called");
    }
}
medium
A. Start method must be static
B. OnDestroy method must return a bool
C. Update method cannot have Debug.Log calls
D. Method awake() should be Awake() with capital A

Solution

  1. Step 1: Check method names for correct casing

    Unity lifecycle methods are case-sensitive. awake() is incorrect; it must be Awake().
  2. Step 2: Verify other method signatures

    OnDestroy() returns void, Update() can have Debug.Log, and Start() is instance method, not static.
  3. Final Answer:

    Method awake() should be Awake() with capital A -> Option D
  4. Quick Check:

    Method names are case-sensitive = Awake() [OK]
Hint: Unity method names must match exact case [OK]
Common Mistakes:
  • Ignoring case sensitivity
  • Thinking OnDestroy returns bool
  • Assuming Start must be static
5. You want to ensure a GameObject cleans up resources before it is destroyed. Which MonoBehaviour method should you override, and what is the best practice to use it?
hard
A. Override Start() and release resources there.
B. Override OnDestroy() and release resources or unsubscribe from events there.
C. Override Update() and check if object is destroyed to release resources.
D. Override Awake() and release resources there.

Solution

  1. Step 1: Identify the cleanup lifecycle method

    OnDestroy() is called just before the object is destroyed, ideal for cleanup.
  2. Step 2: Understand best practice for resource management

    Release resources and unsubscribe from events inside OnDestroy() to avoid memory leaks or errors.
  3. Final Answer:

    Override OnDestroy() and release resources or unsubscribe from events there. -> Option B
  4. Quick Check:

    Cleanup happens in OnDestroy() [OK]
Hint: Use OnDestroy to clean up before object removal [OK]
Common Mistakes:
  • Trying to clean up in Start or Awake
  • Checking destruction inside Update
  • Not unsubscribing from events
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard