0 votes

Hello
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

in Engine by (38 points)
edited by

2 Answers

0 votes

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.

by (136 points)

Tried it, But didnt work

0 votes

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
by (37 points)
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 Frequently asked questions and 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 [email protected] with your username.