How can I add a node via script in EditorPlugin?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By lollornr
:warning: Old Version Published before Godot 3 was released.

get_tree().get_edited_scene_root().get_node(path_to_node) seems not to work!

Can you give some more information about your project? Do you want to create a custom node that adds a node to its parent? Just create the object var foo = Node2D.new() and then add it whereever you want it in the tree with add_child(). get_node() does not add a node it gets an existing node.

umfk | 2016-03-03 16:02

I want to make a plugin in editor that add a child node in the edited scene. I guess there are two trees, one for the editor and one for the edited scene but I can’t access this one.

lollornr | 2016-03-03 21:26

:bust_in_silhouette: Reply From: puppetmaster-
var root =  get_tree().get_edited_scene_root()
var newSpriteNode = Sprite.new()
root.add_child(newSpriteNode)
newSpriteNode.set_owner(root)