PackedScene errore !is_a_parent_of(pnode) is true

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By burstina

I experienced a weird error (i presume) while using PackedScene.pack(node) I never saw before:

the node I want to pack has 3 simple Label children, nothing too complicated

code is:

 var error =PackedNode.pack(curNode)

While pack method returns error=0, the debug window displays:

ERROR: is editable instance: Condition ’ !is a parent of (p node) ’ is true. returned: false
At: scene/main/node.cpp:2037

To avoid this message, I added the following code before the one above:

 for childNode in curNode.get_children():

I presume it is a bug, am I wrong?

:bust_in_silhouette: Reply From: Zylann

The error is a bit misleading because PackedScene was intented to be used from the editor on nodes that you can see in the scene tree dock, which are those that will get saved (i.e packed).

I’m not exactly sure what’s the logic behind the error check, but the doc says this about node ownership:

owner - A node can have any other node as owner (as long as it is a valid parent, grandparent, etc. ascending in the tree). When saving a node (using PackedScene) all the nodes it owns will be saved with it. This allows for the creation of complex SceneTrees, with instancing and subinstancing.

So I guess setting the owner on children you want to save is the right fix.

Also, The More You Know:
By default nodes created dynamically have no owner (or perhaps a different owner?) which is why nodes created by tool scripts in the editor don’t show up and don’t get saved as well. Example: ColorPicker is actually composed of many internal nodes (you can see them if you run a scene with remote scene tree), but these don’t get saved because they are dynamic

sorry for delay, just some rl issues.

This message is also not an error itself, because project get compiled and runs smoothly,

Being not an error and as you write "By default nodes created dynamically have no owner ", ergo pack() method resets owners itself, so there is no reason to dislpay this message at all.

It is juat the kind of message that have Android exports to get mad.

burstina | 2018-11-21 11:43