godot icon indicating copy to clipboard operation
godot copied to clipboard

Assume root when dropping node to unassigned script

Open KoBeWi opened this issue 2 years ago • 4 comments
trafficstars

When dropping a node to Script Editor, you will sometimes get the arbitrary error that the script is nowhere in the scene:

https://github.com/godotengine/godot/assets/2223172/356f5efb-7211-4350-9bd1-c982041dd5a7

The error may appear in valid scenarios, e.g. when dropping node into parent script. In any case, I think it's less relevant now that we have scene unique names, as the hierarchy does not matter that much.

With this PR, if a script is not found in the scene, the editor will assume that the node is relative to scene's root (which, again, is irrelevant if the node has unique name). Here's me casually dropping a node into random EditorScript:

https://github.com/godotengine/godot/assets/2223172/51300850-ba34-4f5b-aebf-c00d0cb3770f

KoBeWi avatar Jul 09 '23 21:07 KoBeWi

The second video shows that @onready ... can be dropped to a script not extending Node, which doesn't make sense / shouldn't be allowed.

kleonc avatar Jul 10 '23 10:07 kleonc

tbh dropping nodes to scripts that don't inherit Node does not make sense, because they don't have get_node() xd I added a new warning: image

KoBeWi avatar Jul 10 '23 12:07 KoBeWi

tbh dropping nodes to scripts that don't inherit Node does not make sense, because they don't have get_node() xd

It could be argued that dropping just the NodePath (drop without Ctrl pressed) should be allowed though. :thinking: I mean Node-deriving is needed only if get_node/@onready is used. There's nothing wrong with having a NodePath in e.g. a Resource (even if that's not recommended).

kleonc avatar Jul 10 '23 13:07 kleonc

idk, I think I never needed node paths in resources. It could be easily implemented if someone wants it, but for now I'd stay with nodes only.

KoBeWi avatar Jul 10 '23 14:07 KoBeWi

https://github.com/godotengine/godot/assets/2223172/0c99b0cc-4ebc-4cce-bfb1-a943c47cf7ec

KoBeWi avatar Aug 01 '23 15:08 KoBeWi

Thanks!

YuriSizov avatar Aug 01 '23 18:08 YuriSizov