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

Using C# and Visual Studio Code doesn't recognize Global Variables created with Project Settings AUTOLOAD #81840

Closed
edwit1971 opened this issue Sep 18, 2023 · 4 comments

Comments

@edwit1971
Copy link

Godot version

v4.1.1.stable.mono.official [bd6af8e]

System information

Windows 11 Pro

Issue description

I created 2 Global Variables (AManager and DManager) inside AutoLoad in the Project Settings and ENABLED the Global Variable checkbox (which was enabled by default.) But in any of my scripts attached to child Nodes of the Node attached to the Script containing the Global Variable Script, Visual Studio Code is highlighting either AManager or DManager references and saying the name doesn't exist in the current context.

Steps to reproduce

Just open the Script files in Visual Studio Code and you'll see the Global Variables are marked as errors and they shouldn't be.

Minimal reproduction project

AutoLoad_Error.zip

@raulsntos
Copy link
Member

That's not how C# works. If you want to access the autoloads you have to use GetNode:

var dmanager = GetNode<DataManager>("/root/DManager");

Have you read the Singletons (Autoload) documentation page? It's documented that this only applies to GDScript but maybe it's not clear enough.

@edwit1971
Copy link
Author

edwit1971 commented Sep 20, 2023

@raulsntos Thank You. I did need to say:

var dManager = GetNode<DataManager>("/root/DManager");

That fixed the global variable being shown as an error by Visual Studio Code. However, DManager is not being created globally by AutoLoad as a node.

When I figure this out I will update here to show how I fixed it. I think I still might not know how to do this properly.

@raulsntos
Copy link
Member

Your MRP is missing the project.godot file, but setting the autoloads like the documentation shows should instantiate them.

What makes you think that DManager is not being instantiated? What does the Scene Tree contain when running the game? You can check using the Remote tab:

image

@edwit1971
Copy link
Author

Okay this is the updated Project for this and everything works.
You are supposed to hit the REMOTE button during run-time to verify that DManager is created Globally.
I didn't know that.
https://github.com/edwit1971/AutoLoad

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