Migrating custom editor data into game

I have a custom editor for manipulating waypoints for pathfinding. I have a few issues with the elegance of it all that make me think I could be doing most of this better, but this is the most troublesome right now. I have one object holding the network of waypoints together, and I have a pathfinding component that pulls up that object and gets this component.

What I was kind of hoping would work was:

  1. I assign the visual editing component that has the waypoint network to the level data object in my editor.
  2. I then do my editing operations, which creates various waypoints that get stuffed into the waypoint network container.
  3. Now in the game, I was hoping a pathfinding component I have on my AI-controlled mobs could retrieve that network and use it.

However, in the actual game, it does not have any of the pathfinding data that it has in the editor. It is completely uninitialized.

Is there some elegant way to bind these together in Unity? All I can think to do right now is add a button to serialize the container and have my pathfinding deserialize it from disk or something. It seems like such a waste because technically, that data is all in there somewhere already.

Can you provide some code, or a rough idea of what classes you’ve defined? I’m envisioning something like this:

  • Class WaypointNetwork (MonoBehaviour): data in public fields, so Unity serializes it, with individual waypoints possibly saved as child GameObjects.

  • Class WaypointNetworkEditor (Editor): custom editor for WaypointNetwork.

You could either assign the WaypointNetwork instance to a public field on your mobs at design time, or they could find it (if there’s only one) at runtime using FindObjectsOfType().

There’s no sense using a ScriptableObject to store the data since waypoints are tied to a scene.