How to get an instance of the current main scene in a static function of another class

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

The situation is as follows:

  1. There is a script attached to the main scene.
  2. There is a separate class script, which has a static function.
  3. There is a signal in the main script, which calls a function in the same script.
    I need to call this signal (emit_signal) from this static function and for this I need an instance of the current main.
    How do I get it without a global variable?
:bust_in_silhouette: Reply From: SnapCracklins

When the script is ready, connect your signal to the outside script. That function name will be your 3rd argument. So assuming “my_custom_signal” is the signal you made (1st argument), target is your separate class object (you’ll have to attach it to a node, maybe a plain Node2d) and then the 3rd is whatever function you want to call.

func _ready():
    self.connect("my_custom_signal", target, "_separate_class_function")