How to place a Sprite after an Animation finishes?

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

So I have some breakable grass in my Action RPG like Zelda, and I want to place some broken up leaves right after the breaking animation plays, but the Sprite just gets placed as the animation plays and not after. Heres the script for better reference:

extends Node2D

const Grass_Effect = preload("res://Effects/GrassEffect/Broken_Attackable_Grass.tscn")
const Grass_Pieces = preload("res://Other/GrassPieces.tscn")

func create_grass_effect():
	var grassEffect = Grass_Effect.instance()
	get_parent().add_child(grassEffect)
	grassEffect.global_position = global_position

func create_grass_pieces():
	var grassPieces = Grass_Pieces.instance()
	get_parent().add_child(grassPieces)
	grassPieces.global_position = global_position

func _on_Hurtbox_area_entered(area):
	queue_free()
	create_grass_effect()
	create_grass_pieces()

And here’s the Grass_Effect’s code to:

 extends AnimatedSprite

func _ready():
	play("Animate")

func _on_AnimatedSprite_animation_finished():
	queue_free()

Please help! I may be making a game but I’m still new to Godot, and I don’t know how I could do this.

:bust_in_silhouette: Reply From: kris_bsx

Hi,
Why don’t you use a Timer or wait for the signal?

func create_grass_effect():
    var grassEffect = Grass_Effect.instance()
    get_parent().add_child(grassEffect)
    grassEffect.global_position = global_position

    # Use "connect" to wait for the "animation_finished" event
    grassEffect.connect("animation_finished", self, "create_grass_pieces")

func create_grass_pieces():
    var grassPieces = Grass_Pieces.instance()
    get_parent().add_child(grassPieces)
    grassPieces.global_position = global_position

func _on_Hurtbox_area_entered(area):
    queue_free()
    create_grass_effect()

Normally when I tried something like this the Engine would say that “it couldn’t connect” or something because the effect had already queue_free before it could send the signal :confused: . I’ll try this method, but I’m not sure if it will work. Thanks for your time though!

EDIT:
yea, I just tried this and it said that it couldn’t get a signal from a “null” thing. All that did was crash my game :/.
Thanks for trying though!

PizzaOnFire99125 | 2020-04-29 18:33