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