This would be a huge time saver if implemented right.
Admit it, the most annoying part is to find nodes by their names from script, especially when scene tree is huge, and when you're moving around nodes and constantly changing layout. Current solution is node groups that are hard to keep track of, but I think there is a better way.
I'm suggesting the ability to drag and drop nodes into script (or right click inside script editor) , but it can be split into three main problems:
I would implement this feature myself but still figuring out how drag&drop was implemented across the editor.
i tried but it's no use, because clicking a node will bring up the right
editor. Just leave this open and will try to find an alternative way to do
it
On Fri, Jun 10, 2016 at 3:46 PM, TheoXD [email protected] wrote:
This would be a huge time saver if implemented right.
Admit it, the most annoying part is to find nodes by their names from
script, especially when scene tree is huge, and when you're moving around
nodes and constantly changing layout. Current solution is node groups that
are hard to keep track of, but I think there is a better way.I'm suggesting the ability to drag and drop nodes into script, but it can
be split into three main problems:
- basically inserting get_node("") statement into the code and filling
in node path automatically.- making scripteditorplugin change all of them whenever a node is
being moved or removed.- for convenience get_node("") statement that is recognized can be
replaced with a button (inside of script editor of course), inside of which
are node icon and node name. Pressing on it would select that particular
node. I would implement this feature myself but still figuring out how
drag&drop was implemented across the editor.—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/5145, or mute the thread
https://github.com/notifications/unsubscribe/AF-Z28meRSpChhgOrSYCuufqry6pR6Niks5qKbERgaJpZM4IzOAL
.
@reduz, I'm ok if 1st & 3rd feature can't be implemented yet, still would be great if script editor kept track of all the get_node() statements and updated them when scene tree changes.
I think that dnd is not only option.
what about add get_node("node/path") at current cursor when ctrl+click in scene tree if script editor is opened?
cause ctrl is usually used for adding something.
dnd is sometimes hard while especially editing text.
@volzhs, well anything is faster than typing, I was thinking more of right-click above the script editor cursor if d&d can't be done, like "Insert selected node path".
@TheoXD both ctrl+click on scene tree and right click on node(contextual menu) would be cool I think.
A "Copy node path" function in the contextual menu would be good too.
I gave it a shot today https://www.youtube.com/watch?v=L7fCntZ9MqY&feature=youtu.be Now I'm trying to make it work the same way autocompletion does, basically evaluating scripts in order to make commands such as get_parent().get_node() to work.
@TheoXD my main concern about this is how it would behave if the nodes are changed while the script is not opened? And what if the same script is added to multiple scenes? You are doing a great work but just keep those caveats in mind.
@vnen, for as long as script is used by any node in the tree - it will be detected. If not opened it will force-open.
I suggest the following:
1) Check if the scene has a dominant script (instanced scenes may have
scripts but you will not really want to work with those in most cases)
2) If so, when opening the context menu, you could show a "Copy path to
root script", you can omit showing this option if no root script
3) Feel free to add a keyboard shortcut for this, since we now have
customizable shortcuts, it can be empty or be something like shift+cmd+c
On Sat, Jun 11, 2016 at 12:05 PM, TheoXD [email protected] wrote:
@vnen https://github.com/vnen, for as long as script is used by any
node in the tree - it will be detected. If not opened it will force-open.—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/godotengine/godot/issues/5145#issuecomment-225368291,
or mute the thread
https://github.com/notifications/unsubscribe/AF-Z2_UL1K962ZMtw6b45gKzIWa3gb9kks5qKs7JgaJpZM4IzOAL
.
@reduz, sure I can add an option for dominant script workflow, so it will only care about root script and nothing else. Still need to figure out how to deal with node selection itself, since it will always bring contextual menu, I think we should change it to double click instead, doubleclicking should bring contextual node editor, single click should just make a selection.
@TheoXD No, having contextual editing on click is a very handy workflow and great for discoverability, we shouldn't break something that works very well for a corner case like this. Just add it to the contextual menu with the other options, if you have to switch back to the script editor it can be a small annoyance but still much better than losing a great feature.
Alternatively, we could make it not open the contextual node editor if you right click to open the contextual node menu, though this can be a little difficult to implement, I could work on it later if an issue is made to fix it
@reduz, or once "Insert Node" (haven't yet decided on the name) has been pressed you should be allowed to click in scene tree dock once, and it would insert on cursor position. This is probably way better and convenient.
@TheoXD I was thinking of something much simpler, just a "Copy path to script" on the node RMB menu, then you go back to script editor and paste it.
Alternatively, something that could be done rather easily is to use a shortcut while writing text to open a popup with the scene tree, where you select a node, press enter and the path is pasted to the script, no clipboard present.
Yeah I will probably go with the last one, seems convenient enough.
@TheoXD okay then, if it helps you can use this one as reference, just copy it to script_editor_plugin.cpp I guess:
https://github.com/godotengine/godot/blob/master/tools/editor/reparent_dialog.h
Really nice work!
I think the idea with a popup with the scene tree is the most convenient too. It is so much nicer if your hands can rest on the keyboard and you aren't forced to use the mouse!
I also would make the inserted code (String path) highlighted when it is updated automatically.
This would make it flexble and fast to use.

I really love your work so far and think this is an awsome feature. The only disadvage I had with nodes so far is that I'm feared to change their order because I don't anymore remember if I acces them in a script. So this feature would help A LOT.
Thank you TheoXD
@reduz, I just accessed SceneTreeDialog, also reused the search/replace functionality provided by FindReplaceBar, since they're both already included and functional.
@toger5, It would probably be best to make this as seamless as possible for the user, so this shouldn't be necessary. If you have an instanced scene with a script attached to it - it won't change anything inside that scene script since everything is relative to the instanced node. Still want it to change paths that point outside of instanced scene, if it goes beyond it's root. But currently seems to work with anything but get_parent().get_node().get_node() chains like that.
@TheoXD okay i see that it is not really necessary. But is it still possible to give it highlighting just so that the user can that this is an automatically updating path.
A little late for this, but how about drag files from FileSystem to append a load("file/path") to script editor?
This has since been implemented.
Although it's very basic and lacks the advanced features discussed here (like updating the script when the dragged node was moved or renamed).
So we might want to keep this issue open. (Maybe rename it?)
I'll close this issue since the core feature was implemented: dragging nodes to the script editor will insert node paths relative to the current script.
Although it's very basic and lacks the advanced features discussed here (like updating the script when the dragged node was moved or renamed).
This is tracked in #3163 :slightly_smiling_face:
Most helpful comment
A "Copy node path" function in the contextual menu would be good too.