Hey there,
I use data coming from external sources (real map data from Open Street Map), thus I have a custom made graph based on that. Every Node as a position but also some useful information for my game:
[Serializable]
public class Node
{
[SerializeField]
protected bool _intersect;
[SerializeField]
protected Vector2 _position;
[SerializeField]
protected List<int> _connected_node_ids;
[SerializeField]
protected List<int> _connected_road_ids;
public Vector2 position { get { return _position; } }
}
My question is, would it be possible to inject, in a way, my custom nodes with all their useful content, into a PointGraph? Then I could easily retrieve informations when I request for a path.
Thanks.
Hi
Yes this is possible. You could for example create a new subclass of the PointGraph like this:
In MyPointGraph.cs:
using UnityEditor;
using Pathfinding;
public class MyPointNode : PointNode {
// additional data here
}
public class MyPointGraph : PointGraph {
protected override PointNode[] CreateNodes (int count) {
var nodes = new PointNode[count];
for (int i = 0; i < nodeCount; i++) nodes[i] = new MyPointNode(active);
return nodes;
}
}
In MyPointGraphEditor.cs (in an Editor folder):
using UnityEditor;
using Pathfinding;
[CustomGraphEditor(typeof(MyPointGraph), "My Point Graph")]
public class MyPointGraphEditor : PointGraphEditor {
}
The other option is to simply keep a
Dictionary<GraphNode, AdditionalNodeInfo> extraNodeInfo;
dictionary somewhere which you can use to look up the extra data.
1 Like
Hey Aron,
Thanks for your reply.
Just FYI, there is no method CreateNode
to override PointGraph
:S What do I need to use here?
Another question, what about saving this graph? Would my custom information saved with it or do I need to write my own saving system?
Thanks.
Hi
It might be that the CreateNodes method only exists in the beta version, Iām not quite sure.
If you want to serialize the data you can override the GraphNode.SerializeNode and DeserializeNode methods in your node class. Node data is serialized in a binary format. You can check out how the other node types implement those methods for example usage.
Hey @aron_granberg, just to know, can you share with us when the CreateNodes method will be out of beta version and hit release version? I could use that
Hi
That is unknown at this time. However you can already download the beta here: https://www.arongranberg.com/astar/download.
1 Like