The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

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

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.

in Engine by (159 points)

1 Answer

0 votes

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 (4,088 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 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.