+3 votes

I want to add some extra nodes to an object and automate it via the following editor script.
Getting the root node of the current scene works and I can change its name but adding child nodes does not. Any help would be welcome.

extends EditorScript 

func _run():
get_scene().set_name("test")            # works
get_scene().add_child(Node.new())       # does nothing
in Engine by (161 points)

This Node.new() seems suspicious to me. Did you try it in the script from an existing scene?

1 Answer

+3 votes
Best answer

working example, the .set_owner() needs to be set for the new node

extends EditorScript 

func _run():

var new_node = Node.new() 


# even if you add it to a sub node set owner only to get_scene
by (161 points)
edited by

Is set_owner still needed? It hasn't thrown any errors when I leave it out.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.