0 votes

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?

Godot version 3.5
in Engine by (123 points)

1 Answer

0 votes

When the script is ready, connect your signal to the outside script. That function name will be your 3rd argument. So assuming "mycustomsignal" 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")
by (548 points)
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 Frequently asked questions and 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 [email protected] with your username.