Consider a Unity script attached to an active GameObject. Which sequence of method calls will Unity invoke first when the scene starts?
using UnityEngine; public class TestLifecycle : MonoBehaviour { void Awake() { Debug.Log("Awake"); } void Start() { Debug.Log("Start"); } void OnEnable() { Debug.Log("OnEnable"); } }
Remember that Awake is called before OnEnable, and Start is called after both.
Unity calls Awake first when the script instance is loaded, then OnEnable when the object becomes active, and finally Start before the first frame update.
Given this script, what will be the output when the GameObject is active and Update disables it?
using UnityEngine; public class DisableInUpdate : MonoBehaviour { void Update() { Debug.Log("Update called"); gameObject.SetActive(false); } void OnDisable() { Debug.Log("OnDisable called"); } }
Think about the order of method calls within the same frame.
Update runs first and logs "Update called". Then disabling the GameObject triggers OnDisable immediately, logging "OnDisable called".
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?
using UnityEngine; public class StartTest : MonoBehaviour { void Start() { Debug.Log("Start called"); } } // Elsewhere in code: // gameObject.SetActive(false); // gameObject.SetActive(true);
Think about when Start is triggered in the lifecycle.
Start is called exactly once per MonoBehaviour instance, just before the first frame update the first time the script is enabled. Subsequent enables after disabling do not call Start again.
Choose the correct method signature for the OnDestroy callback in a MonoBehaviour script.
Check the Unity documentation for OnDestroy method signature.
OnDestroy has no parameters and returns void. It is called when the MonoBehaviour will be destroyed.
In Unity, if Time.fixedDeltaTime is set to 0.02 seconds, how many times will FixedUpdate be called per second?
Think about how fixedDeltaTime relates to FixedUpdate frequency.
FixedUpdate is called every fixedDeltaTime seconds. If fixedDeltaTime is 0.02, then 1 / 0.02 = 50 calls per second.