Recap: Lifecycle Logger
Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 74 of 85.
This recap puts the chapter together: every method Unity calls on a script, from Awake() to OnDestroy(), in the order it calls them.
Challenge
MediumShow Unity's order in the Console.
- Write
Awake,OnEnable,Start,OnDisableandOnDestroy, each logging its own name. - Write
FixedUpdate,UpdateandLateUpdatethe same way, logging only on the first call, with aboolfield each. - In
Update(), on Space, callDestroy(gameObject);.
Press Play, then Space: the Console lists the eight names in order. Then Check.
Try it yourself
using UnityEngine;
public class LifecycleLogger : MonoBehaviour
{
// Log each method's name: Awake, OnEnable, Start, FixedUpdate, Update,
// LateUpdate, OnDisable, OnDestroy. The three that repeat log only once.
// Space destroys this object.
}
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Unity Scripting Basics
1C# Basics in Unity
Hello, UnityVariablesDecimals Need an fText in the ConsoleVariables That RememberIf and ElseCompare NumbersRecap: Coin Collector2Make It Move
Place the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube5Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot8GameObjects and Components
References in the InspectorGet a ComponentMissing ComponentsAdd a ComponentRequireComponentShow and HideRecap: Light Switch6Transforms and Hierarchy
Parents and ChildrenHoist the FlagScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon9Project: Catch the Star
The CatcherA Falling Star12The Script Lifecycle
Awake and StartUpdate and LateUpdateOnEnable and OnDisableThe Lifecycle OrderRecap: Lifecycle LoggerPractice on your own: Unity playground