How to execute a function after other function in another node?

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

I have this tree:

-root
   --PartidaData
   --World
        ---Locations
        ---Camera

On the singleton PartidaData I have a variable “camerazoom”.
When the Camera zooms (animated with a Tween) it changes the value of that variable.
Locations take that value and gets visble/not visible according to that value.

The problem is that as Camera uses a Tween, Locations execute before it ends so doesn’t work as espected.

This is the behaviour, if interested.

I thought about using a custom signal, but it feels hacky.
Thanks.

// use “group” // Groups — Godot Engine (stable) documentation in English

extends Camera2D

  func example():
    if $Camera2D.zoom == Vector2(2,3):
	    get_tree().call_group("group_name", "func_name")
    pass

or Use signal
signal = test

         func example():
           if $Camera2D.zoom == Vector2(2,3):
                   emit_signal("test")
           pass

ramazan | 2022-03-22 11:48

Ok will try it later. So I should call the group from the singleton you say?

chantunRey | 2022-03-22 12:38

:bust_in_silhouette: Reply From: w411-3

Signal’s not too hacky; this is a use case for that. Wait for something to happen, then respond to it. Just make sure your syntax is good.

If you go the “group” route like suggested above, you can call call_group from anywhere in the active scene tree since it’s called on top of get_tree. Doesn’t have to be in the singleton.

thanks! I will go the group way, cause “Locations” is an abstract class and the subclasses will be called.

chantunRey | 2022-03-22 17:37