0 votes

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.

in Engine by (235 points)

1 Answer

+1 vote
Best answer

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:
https://docs.godotengine.org/en/stable/tutorials/misc/running_code_in_the_editor.html

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
https://docs.godotengine.org/en/stable/tutorials/plugins/editor/making_plugins.html#doc-making-plugins

by (2,470 points)
selected by

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

yes

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?

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 )

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

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.