Does using callback and signal pattern makes sense in Godot

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

So I’ve been following this HeartBeast’s episode tutorial on destroying a scene after an animation has ended. I’ve seen his approach and I’m trying to come up with another pattern.

My approach:
Grass.gd

extends Node2D

export(PackedScene) var GrassEffect;
onready var sprite = $Sprite;

func _process(delta):
	if (Input.is_action_just_pressed("attack")):
		onAttacked();

func onAttacked():
	sprite.visible = false;
	var grassEffect = GrassEffect.instance();
	self.add_child(grassEffect)
	var destroy = funcref(self, "destroy");
	grassEffect.playDestroyed(destroy);

func destroy():
	queue_free();

GrassEffect.gd

extends AnimatedSprite

var state;
var onFinish;

func playDestroyed(_onDestroy):
	state = "Destroyed";
	onFinish = _onDestroy;
	self.play("Destroyed");

func playShake(_onShake):
	state = "Shake";
	onFinish = _onShake;
	self.play("Shake");

func _on_GrassEffect_animation_finished():
	onFinish.call_func();

My question is, does this kind of pattern makes sense in Godot? If not, why?

For background, I’m currently working as a web frontend engineer using ReactJS, and this patterns heavily inspired by my daily workflow, so I’m pretty used to using this kind of pattern, but I don’t want to learn bad habit if this is a bad one.

Thanks!

Edit: This is currently discussed in a Reddit thread!

Deni Cho | 2020-05-30 06:59