Godot Version
4.1
Question
@onready seems to work when scene is executed per se, but not when it is instantiated by a singleton.
I followed the tutorial “Cute and Simple Dialog Box | Let’s Godot” (https://www.youtube.com/watch?v=1DRy5An_6DU).
The text box scene works perfectly fine, I tested it. At very least, it does not crash when I run it!
But then in the game I want to call it from the singleton DialogueManager as defined in the tutorial.
Well, in THIS case, the @onready variables label and timer are not properly assigned!!! They remain null, and the project crashes.
IF I assign then “manually” inside the display_text, i.e. if a write something like:
func display_text(parameters):
label = $MarginContainer/Label
etc.
then… it works!
Or, IF I run the scene per se, I don’t need to do add those lines, because @onready works.
But, if I run another scene, put in it a call to DialogueManager to show a dialogue, then the game crashes by telling me that label and timer are null!!!
This is driving me mad.
I mean, I can easily fix it, and I did, by adding two lines to the ready function. Everything works fine now.
But what on Earth is actually happening?! Why is @onready failing, and why only some times and not other times?
Edit: actually this does fix only the “label” part.
Not the timer one.
The timer is not added to the scene tree, never. Godot tells me to add it or set it to autostart. But even if I set it to autostart, it does not work.
There’s clearly a problem with this scene being instantiated by another one, and I’m starting to think it is a bug