0 votes

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.

in Engine by (38 points)

1 Answer

0 votes

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()
by (50 points)

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 :/ . 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!

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.