-
-
Notifications
You must be signed in to change notification settings - Fork 23.5k
Description
Tested versions
- Reproducible in: 4.6.dev [16a11ac]
System information
Godot v4.6.dev (16a11ac) - Fedora Linux 42 (Adams) on Wayland - X11 display driver, Multi-window, 2 monitors - Vulkan (Forward+) - dedicated AMD Radeon RX 9070 XT (RADV GFX1201) - AMD Ryzen 9 9950X3D 16-Core Processor (32 threads) - 60.39 GiB memory
Issue description
When using a custom main loop script through the application/run/main_loop_type project setting, where the script is written in GDScript, and you try to reference an autoload global statically through GDScript from something like its _initialize method, like so:
class_name MyMainLoop
extends SceneTree
func _initialize() -> void:
MyAutoload.greet()... you end up with parser errors saying:
Parser Error: Identifier not found: MyAutoload
However, the autoloads are in fact set up by that point, meaning you can do something like this from a main loop script that derives from SceneTree:
class_name MyMainLoop
extends SceneTree
func _initialize() -> void:
root.get_node("MyAutoload").call("greet")The reason for this seems to be that the main loop script is instantiated before the autoloads are set up and registered, but its _initialize method is called after the autoloads are set up.
Is this just how it has to be perhaps? Is there a good reason for why the main loop is instantiated long before its _initialize method is called?
Steps to reproduce
- Open the MRP
- Run the main scene
- Note the parser error
- Go into
my_main_loop.gd - Comment out
MyAutoload.greet() - Uncomment
root.get_node("MyAutoload").call("greet") - Run the main scene again
- Note how the code runs fine