At the moment i’m trying to implement a dialogue system for my game. The system is very simple and basic.
Each conversation has a staring node
Each node has a line of text, a list of responses, and nodes to link to depending on the response picked. This works but unity starts making noises about the serialization depth limit of 7 because each node can hold a node.
Now i’ve thought about flattening the data out by having a list of nodes in a conversation and then picking them through an index, but this is very unwieldy and becomes invalidated the moment nodes are removed or added to the list.
I’ve heard that using a custom editor script i could have the master list but also set the nodes to refer to other nodes in the list by reference. Before i get into editor scripting though i’d apprechiate a second opinion. What would be a good way to organize this kind of nodal system?
I’m likely going to use a similar node structure for ai decision making so i’d really apprechiate getting a good data design nailed down before plunging in! Thanks in advance for your insights
Give each node a unique identifier, replace all references to nodes with references to the identifiers. This will require some central storage of all nodes.
I’m working on a conversation solution now, and that’s how it works there, using ISerializationCallbackReceiver - when I serialize the nodes, I replace the outgoing connections array with an array of IDs. When I deserialize, I send the list of all nodes to each node, and the node picks out the nodes with those IDs to re-generate the connections array.
A similar alternative is to serialize with a tool that handles object-to-object links. I’m pretty sure fullserializer handles this stuff. It at least claims to do so in the readme.
Make the nodes be assets. If the nodes are scriptableobjects, then the node-to-node reference works as Unity essentially does solution 1 for you. You can use Assetdatabase.AddObjectToAsset to have the scriptableobjects for one conversation be a single asset file instead of a bunch.
ok wow that serialization callback sounds extremely powerful, im just looking in to serialization so this is all new to me but it basically lets you store data as indexes but present it as references right?
This should get around the whole removing nodes breaks indexing problem thank u so much, gonna read up a little