Recap: Lifecycle Logger
Part of the Unity Scripting Basics section of Coddy's Unity journey. Lesson 59 of 67.
Challenge
MediumWrite a script that shows Unity's order in the Console. Each of these methods logs its own name, exactly as written here: Awake, OnEnable, Start, FixedUpdate, Update, LateUpdate, OnDisable, OnDestroy.
FixedUpdate,UpdateandLateUpdaterun again and again, so each of them logs only on its first call.- Space destroys the object, so that the last two get their turn.
Press Play, press Space, read the Console, 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.
}
All lessons in Unity Scripting Basics
1Your First Script
Hello, UnityPlace the CubeMove Every FrameTurn Every SecondSteer with the KeysRecap: Drive the Cube4Vectors
Adding VectorsDirectionsLocal and World SpaceDiagonal SpeedDistance Between ThingsVector3 Is a StructRecap: Drone Pilot7Project: Catch the Star
The CatcherA Falling Star10The Script Lifecycle
Awake and StartUpdate and LateUpdateOnEnable and OnDisableThe Lifecycle OrderRecap: Lifecycle Logger5Transforms and Hierarchy
Parents and ChildrenScaleLook At ThingsMove Toward a PointRecap: Orbiting Moon