-
-
Notifications
You must be signed in to change notification settings - Fork 21k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Autoload global variables behaving inconsistently, properties not having types inferred #77643
Comments
What error if any is thrown? Does this match or not the behaviour when having a node with the same script attached that is not autoload |
That line of code throws the Creating a child node called @onready var not_global: _Global = $NotGlobal
func _ready() -> void:
var num_e = not_global.main.number This matches the erroneous behavior described in #73638, where assigning the result of |
Related to #78454 |
Godot version
v4.0.3.stable.mono.official [5222a99]
System information
Issue description
I've noticed some strange behaviors arising from the use of static typing (along with type casting in general) with autoload global variables.
Here are my findings so far:
class_name
, if it exists.:=
operator if the autoload is .tscn-based, but will if it is .gd-based.The best way I can work around this while maintaining type safety is by only using .gd-based autoloads, but unless I store an explicit reference to the singleton as its proper type, I won't be able to see the full classes of its custom properties.
Steps to reproduce
In the main scene's script,
main.gd
:In the first singleton script,
global.gd
, loaded as a .tscn:In the second singleton script,
global_2.gd
, loaded as a .gd:The autoload configuration:
Minimal reproduction project
TypeBug.zip
The text was updated successfully, but these errors were encountered: