Section 11: Lecture 142: Awake Method Use

I didn’t actually have this particular bug, and I think I avoided this bug by initializing local member variables in my Awake() methods leaving the Start() methods to set up member variables referencing non-local components and objects.

Let me explain my thought process and maybe someone can point out the flaws in it so I can learn for it. Anyway I use the Awake() method to set up and reference variable or value that is locally stored on the game object, basically I use it to set up the object this is how I see the method in my mind as a way to set up a gameObject before it’s called. Then I look at the values that require outside references to other game objects and those get called in the Start() method so ideally anything refenced in the Start() method has already set itself up in the Awake() method and is ready to go.

Now how I think this helped me avoid this particular bug is upon Awake() the enemy health component initializes itself to the default level health value, then in Start() the SaveSystem LoadLastScene() method, called from in the SavingWrapper, overrides the value in the enemy health component with the value it has stored for the gameObject. This is probably a less efficient way of doing this but it makes more sense to me and is stupid easy to implement.

So iunno let me know what I am missing and if there’s another better best practice or efficient way to approach situations like this one, or if I am completely using the Awake() and Start() methods incorrectly.

1 Like

Actually, that’s exactly the process I use! Well done!

1 Like

Privacy & Terms