Post

Code Monkey
Code Monkey@UnityCodeMonkey·
Quick Tip on Awake vs Start in Unity. My one Rule that helps avoid so many headaches is this: Use Awake() for local initialization, meaning for initializing the current object, and use Start() for grabbing references from other scripts. For example if you have a Player with the singleton pattern, you would set the static Instance on the Player's Awake(), but on the Enemy script, if you need to access the Player.Instance you would get that on Start(). That way you know for certain the Player has been initialized before the Enemy grabs it. Stick to this one super simple rule and you will avoid so many code timing issues!
Code Monkey tweet media
English
1
4
41
1.3K
Revolter
Revolter@Revolt3r·
@UnityCodeMonkey One weird thing about Awake is that it’s not called for inactive gameobjects that are instantiated
English
0
0
0
8
Paylaş