2
\$\begingroup\$

I am making a addon for my friends, and I am trying to make a custom node. It works, but I have a problem, the children of the custom node is visible in the scene dock.

Nodes Screenshot

The Text node has children, but they aren't visible in the scene dock. I want the same thing with the Inventory node. (I added the Text, GridContainer,and CenterContainer nodes from another scene through code)

How would I go about this. (Preferably a solutions that uses GDScript)

\$\endgroup\$
2
  • \$\begingroup\$ Just to clarify, do you mean visible/hidden in the Scene dock list of the active scene's nodes (in the editor UI) or do you mean visible in the rendered scene (the game)? \$\endgroup\$
    – Pikalek
    Commented Dec 7, 2023 at 17:47
  • 1
    \$\begingroup\$ Hidden in the Scene dock. I will update the question to include this information \$\endgroup\$ Commented Dec 7, 2023 at 17:55

1 Answer 1

3
\$\begingroup\$

If you are adding nodes from code in a tool script, you need to set their owner in order for them to show in the scene dock and for them to be saved alongside the scene. For example, like this:

add_child(t)
t.owner = self if owner == null else owner

Since you don't want that, you just don't set their owner property (i.e. remove that part of the code).

Bear in mind this means that your custom node must also add its children in runtime since they won't be part of the scene.

You can use Engine.is_editor_hint() to check if your code is running in the editor... But since you want to do the same thing in runtime, you don't need to do that either.

Be aware that since they won't be accesible from the scene dock, the users of your addon won't be able to modify their properties directly or connect signals to or from them directly.

\$\endgroup\$
1
  • \$\begingroup\$ OH THANK YOU! This worked! Thank you @Theraot! Helpful as always! \$\endgroup\$ Commented Dec 7, 2023 at 19:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .