Last active
April 28, 2019 11:22
-
-
Save FlaShG/1f57acefc3a0834882e0fe3a42ac1d1a to your computer and use it in GitHub Desktop.
Learn about Unity's event order when initializing an object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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