Limit Export Variable to Child Nodes

Godot Version

4.3

Question

Is there any way for export var can only choose it’s child nodes in the editor ?

For example I got below nodes in a scene:

MainNode
- Node1 (class : MyNode)
- Node2 (class : MyNode)
- NodeManager (class : NodeManager)
---- Node3 (class : MyNode, child of NodeManager)
---- Node4 (class : MyNode, child of NodeManager)
---- Node5 (class : MyNode, child of NodeManager)
-------- Node6 (class : MyNode, child of Node5)
-------- Node7 (class : MyNode, child of Node5)

And in the NodeManager I have

@export var selected_node: MyNode

In the inspector when choosing selected_node, the node picker will allow all Node1 through Node7 to be selected. But I want only Node6 & Node7 can be selected.
Is it possible to limit export var to child nodes ?

I got it working by making NodeManager to a @tool script and using _get_property_list().
But I prefer not to use tool script.

Is there any other way ?

Instead of using @export you can try @export_node_path

Check out the docs.
Also here.
Some more.

1 Like

Already tried @export_node_path. Still allows me to select all Node1 through Node7. Unless there’s something I’m missing. The doc only mention the arguments are class names. How can we limit it to only child nodes ?

have you tried "./*" for the nodepath to select the children only?

Sorry, could you elaborate ?

I tried below

@export_node_path("./MyNode") var foo

got error “Invalid argument 1 of annotation “@export_node_path”: The class “./MyNode” was not found in the global scope.”

Tried

@export_node_path("./*") var foo

got same error “Invalid argument 1 of annotation “@export_node_path”: The class “./*” was not found in the global scope.”

I played around a bit with this just now, and it indeed doesnt seem possible to only get the children like that. The only thing you could do is:

@export_node_path("MyNode") var foo

So that you only get the correct class as nodes.