Skip to content
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

static vars are not initialized & _static_init is not called on preloaded scripts by tool scripts #81250

Open
IceflowRE opened this issue Sep 2, 2023 · 1 comment

Comments

@IceflowRE
Copy link
Contributor

Godot version

v4.2.dev4.official [549fcce]

System information

Godot v4.2.dev4 - Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1080 Ti (NVIDIA; 31.0.15.3667) - AMD Ryzen 9 7900X 12-Core Processor (24 Threads)

Issue description

Static variables are not initialized and the static constructor is not called on scripts preloaded by tool scripts.
If the preloaded script has the @tool annotation it is initialized/called.

This only affects scripts run in editor.

Steps to reproduce

When opening the project and then opening the scene node you will see this console output:

_static_init of Node
_ready of Node
Node my_var: 32
OtherClass my_var: <null>

Which indicates that the static variables and the static constructor of the preloaded script is not initialized and run.

Minimal reproduction project

static-init.zip

@dalexeev
Copy link
Member

dalexeev commented Sep 2, 2023

If you add @tool to the preloaded script it will work. We have some inconsistency here: in some cases @tool is optional to run dependency code, in other cases it is required (usually Nodes, but in some other cases too, example). I'm not sure if this is a bug as it prevents non-@tool code from being auto-executed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants