I’m currently working with Godot version 4.2.2.stable.mono.official on Windows 10, and I’ve encountered an issue with my C# script. The error message I’m receiving is as follows:
E 0:00:01:0580 can_instantiate: Cannot instance script because the associated class could not be found. Script: 'res://Assets/Scenes/player.cs'. Make sure the script exists and contains a class definition with a name that matches the filename of the script exactly (it's case-sensitive).
<C++ Error> Method/function failed. Returning: false
<C++ Source> modules/mono/csharp_script.cpp:2417 @ can_instantiate()
I understand that this error typically occurs if the filename does not match the class name within the script, considering the case sensitivity. However, in my case, the player.cs script name matches the class name declared in the script exactly.
I’ve tried starting a fresh new project, but the issue remains unresolved and made sure the script is located at res://Assets/Scenes/player.cs. I’ve also made sure to install the latest Dotnet incase it was something related to that. Despite my efforts, the error persists.
Since this is my first project with Godot, I’m stuck on this issue and haven’t been able to find a solution online. If anyone has any insights or suggestions to resolve this, I would greatly appreciate your help!
try open in Visual Studio Code or any c# coding tool, Godot is not enough.
classes from small letter should not affect but you can do right from beginning .
Nope. It doesn’t really have to do anything with the script. Since the error is coming from the name of the class not matching the script name despite the names matching. I don’t think changing the script in anyway will solve the issue.
I’ve tried this already but it just opens a empty visual studio script. Opening it straight from the file just opens it through a miscellaneous file. This also doesn’t change the situation.
Just an update on the issue. I believe it’s because it fails to create a C# project so it’ll make a csharp file without a solution. I think this maybe the issue. This is what happens when I try to build a C# project > tools > c# > create c# project.
It also comes up with an error saying that .NET SDK hasn’t been found but I do have the correct version installed (8.0.6) and I’ve repaired it twice.
I fixed it by deleting everything in the roaming folder of Godot, like the appdata folder. It factory resets the program though, but it shouldnt delete your projects.