Just another quick update about Chant Savant and Unity. I've done a bit more work and added a basic set of Runes, and the tutorial scenarios, and some supporting infrastructure (i.e. dialog boxes and pause games and some more structured services and initialization and such) and a main menu and level transitions. One the one hand not a lot of work for 1 month, on the other hand I've been learning a lot about imgur, so I've got going for me. :) For the next phase I'm actually trying to add some semi-final graphics to the game. I'm hoping to use a style similar to this, since A) I like it B) it lends itself to composition and C) I think I might actually be able to create pictures that style myself. Or at least something close to it.
A now for the regularly scheduled Unity jank. Overall I've really been digging the platform. In particular the way the Unity Beta lets you design UI's is great, it is fast and flexible and looks neat and makes a lot of sense. I've only been using the UI for relatively simple things so far, but with the way you can mix and match and composite elements has really been fun and you can see how you could easily make more complex elements with it. The anchor system can be a bit confusing, but I'm not sure if that is accidental complexity or simply required for the problem they are solving. Still, despite the above love, every week or so Unity will reveal another "wat" that it's been hiding. For this month we have:
- Equality: I'm running the game, and I get a null reference exception. Ok, I look at the code, which isn't that complex, and it's like well, it is logically impossible for that value to be null. Thirty minutes later I find the reason, Unity has overriden the equality operator so that inactive/removed GameObjects report that they are null. :( After reading some blog posts I can *kind* of see the reasons why they did it (so that you don't have to check if a dead/inactive gameobject should carry out its logic), and why they haven't fixed it (it would break lots of existing project code), but man, way to kick the new users in the nuts.
- Find: I spent the longest time trying to figure out why I wasn't able to look up new objects that should have been created in the Scene. Certainly it's because they are the first Prefabs I am using, or maybe it's this new UI element's fault? No, it's this weird thing where if you make an object inactive, then the GameObject.Find() call won't actually find it. My understanding is that you can never, ever look it up again? Which can't be right. Lol, anyway it seems like you need to keep a reference to the object or an object path to it if you ever want to use it again. So, now my objects never go inactive, they just get shunted off to the x=10000 dimension, waiting for their moment to be moved back into the view area.
- Order of Script Execution: During the previous weeks with Unity I'd built up this head-canon about the order that scripts are executed in. The GameObjects in the scene are processed from top to bottom in the hierarchy, and inside each GameObject the scripts are executed in the order that they are listed. So when I'd add a new script to an object, I'd try and move it around in the script list to the place I thought it needed to be. Lol, nope. It's all completely random! Or rather it's not completely random, but depends on some combination of your machine, time of day, the names of scripts, the order in which the scripts and GameObjects were first created, etc. etc. Great Unity, just great. The long and short of it is that I've made my own simple initialization system on top of Unity's. It's worked well so far. This way I can just have X number of initialization stages (rather than the 2 that the default Unity objects have), and then just place the initialization for each object in the phase that makes sense. It's a lot cleaner, and keeps most of the initialization in code, which I like.
- Debugging: And of course, as usual the debugger will just flat out crash the Unity Editor about ~5% of the time. Make sure to save and backup your work before you do anything too crazy.