I'm working on the data side of an MMO and the amount of time and effort spent on serialization alone is astounding. You'd think something like this would have a clear, mature solution.
I kind of feel that way about a lot of Unity ;-)
Player interaction with maps! Editing live in edit mode!Feb 5 - Properly serializing map data for Unity
Huh, I missed a few days there. Not that I haven't been working, but I just ran out of time at the end of the day to write up my progress here, for one reason or another...
On Saturday and Sunday I was procrastinating working on the game, so I worked on some music for the game instead, which is coming along nicely! I'm not exactly sure where I'm going to use it though. My approach to music is always to let the song do what it wants rather than to guide it, and the song is coming out
far too happily for such a moody game. :-) Maybe I'll have to switch up the mood of the game a little. As much as I've been drawn to dark moody stuff, my strengths have always lied in the more up-beat and humorous stuff. Then again, I just watched
Three Billboards Outside of Ebbing, Missouri and it combined moody with humor really well. Maybe I could use that sort of approach. Harum. Anyways, I'm getting off topic!
Today the majority of my time was spent learning how to correctly serialize data for Unity. This meant learning all of Unity's idiosyncratic serialization rules, like adding [Serializeable] everywhere and then writing my own custom Dictionary wrapper class that wasn't generic so that I could use that everywhere instead of C#'s native Dictionary (since Unity can't serialize generics, except it can serialize List<T> for some reason. Don't question it.). This feels pretty insane to me, and it's not even the most insane thing I encountered today. I ran into an extra nasty bug where Unity was deserializing the same object three times when I only expected it to do it once. It was the first time in a long time where I've just been utterly baffled by a bug. I stared at the computer for like 10 minutes, gave up, came back, stared for 10 minutes, gave up again, and repeated that process like 5 times before eventually logging every single function call so I could see exactly what was going on. That proved to be the winning approach to understanding the bug, so maybe I should remember that for future tricky problems.
Anyways, once I got serialization working, that meant that I play the game and Unity would properly serialize all my maps and my character could interact with them, which was neat! However I was immediately stymied by another problem, which was that if I made edits to the map in Play mode, then when I finished playing, all my edits would be reverted.
So I casually searched for how to carry over edit mode changes into google...
...and then I clicked through a few results...
...and then 30 minutes passed...
...and then I started begging people on Discord for some way to do it because I was sure I was missing something obvious...
Nope, turns out I wasn't missing anything obvious. Unity has not implemented this INCREDIBLY TRIVIAL AND HUGELY IMPORTANT FEATURE. When I said "not the most insane thing I encountered," THIS was the most insane thing I encountered today. HOW IN GODS GREEN EARTH IS THIS POSSIBLE. Someone on Discord helpfully suggested ScriptableObject though, and that was really useful, especially because I watched this Youtube video the other day about how you should use ScriptableObject for everything. So I hooked up ScriptableObject for my map serialization data and BOOM, now I can edit maps in Play mode and the edits will persist even after the game is over! How awesome is that?
Anyway, I am feeling quite pleased with this Voxel World Editor that I've whipped up over the last week, and I think it's time to move on to something else, finally!
I know I keep saying that, but this time for real.