0 votes

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
        get_parent().add_child(explosion)
        queue_free()

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)
        return collision.collider.name

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

set_name(name_of_asteroid)

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

in Engine by (135 points)

1 Answer

0 votes

Hi,
do you know that names have to be uniq? So when you spawn the scond "smallasteroid" it will be automaticly renamed to "smallasteroid2".

You could at anytime call gettree().getroot().printtreepretty () to get the current sceneTree setup into the console. This should shed some light on it.

by (3,928 points)

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

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.