Godot Version
4.2
Question
I have a plugin that adds some needed nodes as children when creating that node. For example, creating an Area2D
will add a CollisionShape2D
with a RectangleShape2D
as the shape. Here’s a simplified version of my code:
func on_node_added(node: Node):
# node isn't created, just displayed on scene load
if node.get_child_count() > 0: return
if node is Area2D:
var new = Node2D.new()
node.add_child(new)
new.owner = node
This works both when creating a new scene and when adding a node to a scene, but when the node is created in the scene, the child node doesn’t show up in the inspector.
Here’s a tree of this example:
scene_root
|
___ new_node // no child shown here, but exists when checked with `get_children`
And here’s creating it on a new scene. Notice the added node as a child.
new_node // (scene root)
|
____ created_child_node // shows up here
Any ideas as to why this happens, and how I can fix this?