Godot Version
4.2
Question
Hi, I’m following the official Creating your first script guide provided by Godot, trying to do it in C#, but it doesn’t work at the end returning the following error:
E 0:00:00:0730 can_instantiate: Cannot instance script because the associated class could not be found. Script: ‘res://sprite_2d.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 have set up visual studio code in the dotnet configs and installed the SDK for C#.
the script is correctly referenced in the Sprite2D node and it returns the error above.
The C# script is the following:
using Godot;
public partial class MySprite2D : Sprite2D
{
private int _speed = 400;
private float _angularSpeed = Mathf.Pi;
public override void _Process(double delta)
{
Rotation += _angularSpeed * (float)delta;
var velocity = Vector2.Up.Rotated(Rotation) * _speed;
Position += velocity * (float)delta;
}
}