How to use custom navigation graph from *.gd script in scene?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Robotex

I implemented custom navigation graph and pathfinding algorithms in few *.gd scripts as extensions of Object.

Graph has functions like addNode/addEdge and removeNode/removeEdge that allow to create it.

Everything is working if I manually create graph.

But how can I create this graph from Editor? Ideally, if it can be done automatically (for i.e. with some kind of flood-fill algorithm).

Can you give me some advices or examples how can I add functionality for graph making to editor?

Should I create this graph in the _ready() function of scene? But ideally to do this on the editing stage and just save graph to file.

P.S. I’m making tactical pathfinding for my game, so, I need custom navigation graph.

:bust_in_silhouette: Reply From: klaas

Hi,
if i understand correct you want to integrate your self coded navigation system in the editor.

Have a look at the tool feature here:

a simple trick to trigger an action in the editor when in tool mode is

export(bool) var update = false setget _set_update #<-will be called when changed in inspector

func _set_update(value):
     #just dont set the value, make your update
     do_the_update()

or if you need more features read about making plugins here

you want to integrate your self coded navigation system in the editor

yes

Robotex | 2020-09-01 09:25

I can’t clearly imagine what functionality should this plugin provide to create needed navigation graph nodes and edges for the given scene.

I imagine it like I should click on button at editor, then click somewhere in scene and set maximum amount of iterations and then recursive algorithm will make this graph. Is my vision correct?

Robotex | 2020-09-01 09:28

To precompute you graph you have to run code in the editor.
For that you have to write a tool script to do so.
Collect all needed informations for your precomputing via export variables.

The starting point for your flood-fill-algorythm could be the tool nodes position in the scene.

tool
extends Position3D
class_name myNavGraph #will appear under this name in create node

export(float) var resolution = 1.0 #example of needed informations
export(bool) var update = false setget _set_update #<-will be called when changed in inspector

func _set_update(value):
     #just dont set the value, make your update
     var start_at = transform_global.origin
     analyse_scene_make_graph( start_at )

klaas | 2020-09-01 09:35

remember … you have to store your data somehow.
You can infact make your own resource object. But that is another subject.

klaas | 2020-09-01 09:44