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:

extends Node2D

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

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

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

func destroy():

extends AnimatedSprite

var state;
var onFinish;

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

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

func _on_GrassEffect_animation_finished():

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.


Edit: This is currently discussed in a Reddit thread!

Deni Cho | 2020-05-30 06:59