Skip to content

Instantly share code, notes, and snippets.

@FlaShG FlaShG/EventOrderTest.cs
Last active Apr 28, 2019

Embed
What would you like to do?
Learn about Unity's event order when initializing an object.
using UnityEngine;
public class EventOrderTest : MonoBehaviour
{
private bool firstUpdate = true;
private void Awake()
{
Log("Awake");
}
private void OnEnable()
{
Log("OnEnable");
}
private void Start()
{
Log("Start");
}
private void Update()
{
if (firstUpdate)
{
Log("First Update");
firstUpdate = false;
}
if (Input.GetKeyDown(KeyCode.Space))
{
Log("Before Spawn");
gameObject.AddComponent<EventOrderTest>();
Log("After Spawn");
}
}
private void Log(string s)
{
Debug.Log(gameObject.name + ": " + s);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.