0 votes

Hello all, Im creating a battle system (rpg) and when the battle starts I instancing the monsters using the code:

var mons1 = preload("res://Scenes/Batalha/Monstro1.tscn")
var mons2 = preload("res://Scenes/Batalha/Monstro2.tscn")
var mons3 = preload("res://Scenes/Batalha/Monstro3.tscn")

And instancing it:

var m1 = mons1.instance()
var m2 = mons2.instance()
var m3 = mons3.instance()
add_child(m1)
add_child(m2)
add_child(m3)

My questions is: how can I check if the monster are in the tree? In game maker its instance_exists(m1)

in Engine by (171 points)

1 Answer

+1 vote
Best answer

I have to correct my answer, is_instance_valid() is used to check if an object was previously freed.

You can use has_node() to check if a node is in the tree.

parent.has_node(m1)
by (1,457 points)
edited by

Thx so much dude :D

I corrected my answer since it wasn't right.

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.