Instancing and checking

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

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()

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

:bust_in_silhouette: Reply From: Adam_S

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.


Thx so much dude :smiley:

DarlesLSF | 2019-10-18 01:16

I corrected my answer since it wasn’t right.

Adam_S | 2019-10-18 04:23