how to load a scene and add as a child node?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Thakee Nathees

I have a scene enemy.tscn and inside a Node2D I want to load the scene and add the scene as the child for Node2D. but the load(res_path) function returns a Resource, and the Node.add_child(node) mehtod need a node as it’s argument. how to resolve this?

:bust_in_silhouette: Reply From: Dlean Jeans

Use instance():

var enemy = load(enemy_path).instance()
add_child(enemy)