Need some help with custom graph implementation (showing the graph in the editor's scene view)

Hi!

I’m working on a custom graph (hexagon grid) and so far it’s going pretty well. I do have an issue though with showing the graph in the scene view. The graph shows just fine after a (manual) Scan but if I change scene to work on something else and come back to the scene with my graph, it doesn’t show, even whith Scan on awake set to true. It doesn’t show either when I close Unity and restart it. I have to manually scan the scene for the graph to show.

I’m wondering what I’m missing in my code to force the graph to show on startup or on scene change.

Another thing : if I open unity and the graph doesn’t show, and I press play to run the scene, the graph is there. My test agent finds paths to wherever I want him to move. Then I stop the game and, back to the scene view (which showed all node connections when the game was running), the graph doesn’t show anymore.

Thanks for the help!

Hi

The graph data is not serialized in the scene, so if you switch scenes and later come back to it, it will not know how the graph looks like until you have recalculated it again.
This is the same with the built in graphs.

You could force it to be scanned in e.g OnInspectorGUI or in OnDrawGizmos, but I would advice against that.

The reason the data is not serialized is because it is simply too large in many cases. I have seen people with graph sizes so large that the graph data has been in the hundreds of megabytes.

Scan On Awake will scan the graph when the game starts, but not in the editor when the game is not running.

Also note that there is a shortcut to scan the graph: alt+cmd+s on Mac - alt+ctrl+s on Windows.

Hi Aron, thanks for the uber-fast response!

I’m thinking there is an issue because if I add a grid graph besides my hexagon graph, save the scene, change to another scene and come back, both graph are shown in my scene view, although it seems to be causing an error, logged in my console as follows :

ArrayTypeMismatchException: Source array type cannot be assigned to destination array type.
Pathfinding.Serialization.AstarSerializer.DeserializeEditorSettings (Pathfinding.GraphEditorBase[] graphEditors) (at Assets/AstarPathfindingProject/Core/Serialization/JsonSerializer.cs:787)
AstarPathEditor+c__AnonStorey2.<>m__3 (Boolean force) (at Assets/AstarPathfindingProject/Editor/AstarPathEditor.cs:2391)
AstarPath.ProcessWorkItems (Boolean force) (at Assets/AstarPathfindingProject/Core/AstarPath.cs:812)

Can this be an scan issue or is it related to something else ?

Hi

That is a bug in the system at the moment.
Try the fix recommended here: http://arongranberg.com/vanillaforums/discussion/comment/2249/#Comment_2249
and see if it helps

The link mentioned here does not work. Can you update the link?

Thank you

Hi

This post was from more than 2 years ago. I believe the issue has been fixed already.