The presenter in the Scavengers tutorial barrels along faster than I can type, and I'm not slow. I was pretty sure I'd miss something. And I did. My food and soda wouldn't pick up and it took me a long time to realize I'd misnamed my method with 2d instead of a 2D.
But what really got me wasn't something I could control. When my level was resetting, it wouldn't recreate the board. I changed from a deprecated method to the new loadscene version. And then I started putting in debug.log statements (didn't I say this felt like old school VB once before?). After trying to narrow it down, it appeared my Awake function wasn't triggering, so the board wasn't repopulating. I compared their completed version with my version of the script, and the prefab, everything else, all to no avail. Finally, in this five year old post (long before the current version of Unity) someone mentioned that Awake() doesn't always refire and you have to code it up under OnLevelWasLoaded() to catch logic after the first time. I dropped it in there - cut and paste rather than appropriate refactoring - and success! So for anyone else who's getting Awake() or InitGame() events that aren't firing when they expect them to, OnLevelWasLoaded() is a good place to call your logic again to be sure it triggers.
You can see the affect of the bug on not rebuilding subsequent levels in the video.
No comments:
Post a Comment