the character death function does not work with created objects in the script

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

I have a function for the player and extends on global script

func die():
    var colider = get_collision()
    var colider_name = get_collision_name()
    var explosion = load("res://scenes/explosion.tscn").instance()
    if colider_name == 'small_asteroid' or colider_name == 'middle_asteroid' or colider_name == 'big_asteroid':
	    asteroids.before_die(colider, colider_name)
	    explosion.position = global_position

and functions in the script global

func get_collision():
for i in get_slide_count():
	var collision = get_slide_collision(i)
	return collision.collider

func get_collision_name():
    for i in get_slide_count():
	    var collision = get_slide_collision(i)

if I add asteroids to the scene myself, the player’s script will work, but if I add asteroids through the script, the player’s script will not work. I noticed that the created asteroids have different names that I check in the player script. I tried to change their names by adding the asteroids themselves to the script


but it didn’t work, can anyone please show me the code how this can be solved.

:bust_in_silhouette: Reply From: klaas

do you know that names have to be uniq? So when you spawn the scond “small_asteroid” it will be automaticly renamed to “small_asteroid2”.

You could at anytime call get_tree().get_root().print_tree_pretty () to get the current sceneTree setup into the console. This should shed some light on it.

thanks, I figured it out. In the evening, the head does not work, and in the morning I almost immediately found a solution)

Timofey | 2020-09-14 06:30