how to use the addchild method with Packedscene in c# PLEASE

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

I want to spawn enemies randomly and according to what checked the most popular way to do it is to instantiate a scene and using the Add_child.
But, this method only takes node as an argument , and not packed .
how do I solve this?

And another questiob
To what I know,var is only useable inside the Ready function how can use these variables outside the ready func

thx in advance

:bust_in_silhouette: Reply From: Regulus

While I don’t use C#, in gdscript you would call .instance() on the PackedScene, which returns a node that you can add as a child.

Tried it, But didnt work

godotuser123 | 2022-09-06 20:27

:bust_in_silhouette: Reply From: suribe

As already answered, you should first instance your packed scene.
For example:

PackedScene scene = GetSceneFromSomewhere();
var node = scene.Instantiate();
AddChild(node); // assuming you want to add it to the current node