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

Autoloaded scripts not generating nodes under root in C# #39444

Open
stephen-soul opened this issue Jun 10, 2020 · 2 comments
Open

Autoloaded scripts not generating nodes under root in C# #39444

stephen-soul opened this issue Jun 10, 2020 · 2 comments

Comments

@stephen-soul
Copy link

I searched but couldn't find anything. If this was already noted, oops. Also, if this isn't even a real issue and only exists with me.. I'm sorry.

Godot version:
Godot 3.2.1.stable.mono.official

OS/device including version:
Ubuntu 18.04 using VSCode 1.45.1

Issue description:
This might be random and super niche but hey, maybe this is something not only I ran into. Basically, in GDScript I'd just use the editor to make a new .gd file, set it as my autoloaded script and now I basically have a singleton. I've tried doing the same thing in C#, except using VSCode, and realized that the engine was throwing an error every time saying that my script wasn't inheriting a node.

Fast forward to me wondering if it was sleep induced confusion and I realized that if you generate a cs file through VSCode and then set it as an autoloaded script in Godot, it wont create a Node under root for the script and it just wont load.

Steps to reproduce:
Load the attached project in the engine, run the game, note the error that pops up about the script not inheriting node.

To fix, create Node as child in scene, attach script to this new Node, delete Node, run game and now it works.

Minimal reproduction project:
autoload-not-loaded.zip

@hawkerm
Copy link

hawkerm commented Jun 29, 2023

I'm on v4.1.beta2.mono.official and am also having trouble with an autoloaded C# script. I can call it with the GetNode<MyType> syntax and path when adding it to my project settings, but if I check Enable to have it auto-generate the instance for me to access directly in my C# code it doesn't seem to be available, even if I give the instance name in the Autoload UI a different name than my class.

@raulsntos
Copy link
Member

@stephen-soul Your MRP doesn't have a .csproj or .sln files. These files are generated automatically by Godot when creating C# scripts from Godot.

If you are creating C# files from outside Godot (i.e.: from VSCode) then these files won't be automatically generated, you can still manually generate them from Godot using the Project Tools > C# > Create C# solution option.

The .csproj and .sln files are necessary for Godot to detect your project as a C# project and load C# scripts; otherwise, your C# scripts won't be loaded.

You'll notice when Godot has detected your project as C# project when a Build button shows up in the top-right corner of the Godot editor, and the MSBuild panel appears in the bottom dock.


@hawkerm You haven't provided an MRP so your issue may be caused by something else. Please, open a new issue with a minimal reproduction project attached.

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

4 participants