This is a possible bug, but before I submit a report I thought I would ask here just to make sure.
In the Main Scene, I can instantiate an asset that has a button attached to it.
Scene layout:
_Node2D (script)
|_Button (calls script.method)
On script: @onready var myScene = preload(“res://path/to/myScene.tscn”)
func _ready():
var instance = myScene.instantiate()
add_child(instance)
The scene shows as desired, and the buttons in the scene work. Now, if I move this code to a script that is autoloaded, the scene shows up just the same but the buttons do not work. The buttons show, but their signals do not go through.
I should mention that I am using the preloaded script as a static singleton. I am not instantiating the preloaded script, just calling methods on it. This might be the issue, but if so then how do I make proper globally accessible singletons?
Can you show your Autload panel? The preload in your example is a scene, not a script. Are you autoloading a tscn? Or trying to manually instantiate with a gd?
There is no tscn associated with the singleton class. It’s just a script. The tscn that I am instantiating with instantiate() is a scene with a tscn. Apologies on the error in my last message. @gertkeno, not trying to be rude, but do you get what I mean when I say that I’m creating a singleton class in the global namespace? Every framework has their own way of describing things, and Godot does not have static. But I do see in the docs that autoload is intended as a way to create singletons, which is what I’m going for. It’s odd to me that everything else in the singleton class is working fine, just not instantiating scenes with pre-configured signals.
The code you posted works just fine. I tested it locally. So there’s something else going on. Please post more context. Relevant scripts, configuration, scene structures, etc.
I don’t think you are giving us the whole picture, The script example you posted can be reduced by putting whatever script you need on the root node of res://path/to/myScene.tscn and autoloading that scene instead of just the script. The script example also has no signals or connections so it’s impossible to discern a signal/connection related error from it.
Let me try and explain it a bit better too. There is a scene that I am instantiating which has a control node root and a button that calls the control node’s script. If I instantiate the scene from the main scene, it loads in and works fine. But if I instantiate the scene from an autoloaded script, it looks fine but the button does not work. Does that make more sense now?