It feels like the time between posts is getting shorter, which is odd because my days are definitely feeling longer! Did someone break the space-time continuum again? You have to stop doing that. Let’s jump in.
My continuing quest to make level creation a breeze… er… continued… while you’ve been gone. Last week it was time to think about saving and loading. For this I needed to decide how I wanted to store my levels. I’ve already written a bunch of code that loads scene files (Check the Background for non-techies for a quick summary of scenes), but scene loading is a whole thing, and because my levels are pretty small fundamentally, I’m not sure it’s worth all the clean-up and whatever nonsense Unity does under the hood. So I switched over to prefabs (we covered those in the last blog). I decided to ignore the level loading in-game code for the time being, and leave that for future Matt, and instead focussed on simply getting the editor to save out a level into a prefab. It took some memory jogging, and some Googling, but long story short, it works! The save button will save the prefab into the levels folder, with the name given in the Level Settings object, and it even autosaves every three minutes and when you load a new level!
Loading into the editor took a little longer; I wanted two methods of loading, one where you pass in the object to load, and another, where you write the level name, and it looks up the level manually to load in. Both of these methods involve our good friend the Resources folder. Now if you recall, anything in a folder structure with “Resources” in the path will always be loaded into the final package. This can get problematic, but we definitely want every level to be in the build so I figured this would be ok. So whenever you manually save, it saves in “…/Resources/Levels/”, meaning it will be locatable in the content browser, without needing to be stored in a scene or object anywhere. Autosaves are stored outside of the Resources folder so we don’t bloat build sizes. Eventually though, I was able to load via both methods, and my editor is much nearer completion!
I rounded the day off by adding a method of loading in an obstacle from the editor script, which uses the Theme Package code I wrote previously and creating the prefabs for the guidelines and the base level. The finished result looks like this:
Next on the agenda, rewrite the game level loading code to use these prefabs instead of the scene files!
Now for something completely different. Of late, some spam spider has been crawling in my website. Specifically Making AI Go and Playing in the Snow. As a result, there have been a lot of rogue comments from less-than-reputable sources appearing with middling frequency. I’ve mostly been deleting them, and I finally got around to adding some filters today that should deal with most of the throughput. However, the first one gave me an excellent excuse to put together a new video. I strongly recommend you check it out:
It’s pretty fantastic right? I thought it was worth keeping! Anyway, that level loading isn’t going to code itself, and I’ve yet to get the theme stuff working. Those are my next challenges I reckon. And hey! I managed to keep on #EgoProblems for a whole post, that’s gotta be a first!
Matt out.
<3