Godot: add_child in tool script reflected in editor view but not scene tree

Created on 2 Jan 2020  路  4Comments  路  Source: godotengine/godot

Godot version:

3.1.2.stable.custom_build

OS/device including version:

Linux 5.4.6-arch1-1 GNU/Linux

Issue description:

When a tool script adds a child to a node, you can see the node in the 3D view, but not in the scene tree.

Steps to reproduce:

  1. Create a scene with a Spatial root
  2. Create another scene with a MeshInstance and add a Mesh
  3. Add the following script to the spatial
extends Spatial

export(PackedScene) var scene: PackedScene setget set_scene,get_scene

func set_scene(val: PackedScene):
    scene = val
    add_child(scene.instance())

func get_scene():
    return scene
  1. Place the PackedScene from step 2 in the scene field via the editor
  2. Note that the MeshInstance is visible, yet not shown in the scene tree

Minimal reproduction project:
example.zip

1577931482

documentation enhancement

Most helpful comment

Duplicate of #12456? Perhaps add_child's documentation should have a note mentioning set_owner added to it.

All 4 comments

Wasn't this done by design to prevent persisting the added nodes to the scene file? I'm not sure.

That actually makes sense, and in my case I wouldn't want it persisted. Feel free to close if this is intentional.

Duplicate of #12456? Perhaps add_child's documentation should have a note mentioning set_owner added to it.

Duplicate of #12456? Perhaps add_child's documentation should have a note mentioning set_owner added to it.

good idea! Especially for beginners it's quite confusing when they start working on tools

Was this page helpful?
0 / 5 - 0 ratings