godot
godot copied to clipboard
Can't preload a scene in AutoLoad script when the scene's script references the AutoLoad
Godot version
4.0.alpha3
System information
Windows 10
Issue description
This appears to be a regression in 4.0, as this works in 3.4.3. Running the scene causes a ParserError crash, when I expect it to run fine.
Steps to reproduce
If you have a simple AutoLoad script like so:

Which preloads this simple scene with just one script:

And that script references the AutoLoad script:

Then running the scene causes a crash:
Parser Error: Could not preload resource file "res://Scene.tscn"
Minimal reproduction project
Working project in 3.4.3: AutoloadBugGodot3.4.3.zip
Identical project but in 4.0.alpha3: AutoloadBugGodot4.zip
I just came here to report this very issue in alpha 6. Glad to see it's already a known issue. Hope to see it resolved soon.
Just had the same issue in v4.0.alpha13.official [59dcddc45] And maybe this is relevant for fixing this:
When running the project from the editor, one can just 'Continue' twice in the debugger and everything seems to work as expected. This can also be seen in the minimal reproduction project above.
In my case I can even confirm that both the reference to the preloaded scene, aswell as the usage of the autoload works afterwards.
Still present in the v4 beta, and continuing twice also proceeds past it
Using load instead of preload does work fine though (at least in 4.0-beta1).
Not sure if there's actually any practical difference between load and preload for a variable in an AutoLoad script, if the loading is done at the top (outside of any function)? Either way it gets loaded immediately, right?
(obviously there's a difference if the preload is to be done inside a function)