Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save RichardEllicott/359a80c386913ce33d5936b4f04f6007 to your computer and use it in GitHub Desktop.
Save RichardEllicott/359a80c386913ce33d5936b4f04f6007 to your computer and use it in GitHub Desktop.
get or create a node in Godot, stopped working some point in 4.1.x
## get existing or create new child node, works in tool mode to show in editor
static func get_or_create_child(_parent, _name, type = Node3D) -> Node:
var child = _parent.get_node_or_null(_name)
if not child:
child = type.new()
child.name = _name
_parent.add_child(child)
if Engine.is_editor_hint(): # if in editor we need to do this to show in editor
child.set_owner(_parent.get_tree().edited_scene_root) # new, allows static
return child
@RichardEllicott
Copy link
Author

hell okay it sorta works sometimes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment