Kingdom Of Galanor

From our thread on the Unity Forums

In my last update, I forgot to mention the headache I faced trying to save the waypoint data in the NPC custom inspector. As I was working with an array I couldn’t use the SerialisedObject system for that part, so I was using Undo.RecordObject, but during testing, I found that Undos were causing the array element order to get mixed up.

It took me a while to discover that I needed to use Undo.RegisterCompleteObjectUndo instead to avoid this happening. Which was great, but then the exact same code that was now working perfectly in my test scene completely failed to save the data in my actual game scenes!

I spent nearly a day trying to figure this out until I stumbled across the nugget of information that scene instances of prefabs also need to have PrefabUtility.RecordPrefabInstancePropertyModifications used on them to make sure the changes are saved to the underlying scene object. (My test scene wasn’t using an instance of a prefab for the NPC object, unlike my game scenes.)

There again, the Unity documentation regarding this is either missing completely or not that easy to find. Such a pain!

Anyway, that aside, I’ve added extra functionality to the NPC pathing system that now makes it possible to simulate them entering and leaving buildings (or anything in the map for that matter). Waypoints can now be configured to pause the NPC for a given amount of time when reached and optionally hide the NPC when paused, and also optionally warp to the next waypoint.

Demo video of this (speeded up 6x)

I haven’t made it so that NPCs can actually travel to other maps, because even though it’s possible the amount of work involved would far out way the usefulness of it.

Two update posts in 3 days, I’m on a roll 🙂