Created
November 9, 2023 17:19
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hell okay it sorta works sometimes