Reference the current lambda function?

Godot Version

4.4.1.stable

Question

Is it possible to reference the lambda or the parent function of a certain scope of code? For instance:

Loader.resource_loaded.connect(
		func():
			current_level = ResourceLoader.load_threaded_get(level).instantiate()
			# disconnect to this lambda to the signal
)

In this statement ^ I create a new lambda/callable and connect it to my custom Loader autoload signal resource_loaded and then use it to set the current_level and disconnect to the signal resource_loaded. However, I can’t do that since there is no way to reference the lambda, I would have to move all this code to a different function, which is not ideal.

Is there anyway to reference it? So far I’ve been looking and I haven’t found a concrete way.

You can assign a lambda to a variable, though the difference between that and just declaring a local function is probably moot.

1 Like

You can connect with the flag CONNECT_ONE_SHOT in this case

This isn’t a perfect solution, as it won’t work with anything that’s not a signal. But it’s good enough for this case. Thank you!