#Cannot instantiate C# script because the associated class could not be found

1 messages · Page 1 of 1 (latest)

heady niche
#

I'm recently watching someone introducing me to godot and with c# support and so I followed all his steps to setup godot and c# and make my first project labeled as "GemCatcher" and so I followed all his steps on what to do until it was time to run my first script on the project but this error message kept popping up whenever I ran anything

(Cannot instantiate C# script because the associated class could not be found),

I even tried to search for people that have the same problem but there fixes didn't work for me

lavish tangle
#

all godot script classes need to be partial

#

eg public partial class Paddle : Area2D

#

same with any of your other script files

heady niche
#

and put "partial" for both of the scripts

lavish tangle
#

other than that it looks fine. it might be something to do with the way you're running it

lavish tangle
#

try running it from the godot editor instead

heady niche
hearty patio
supple wraith
#

Your code either doesnt build or isnt builded yet. Thats why Godot tells you he cant find the classes.
The Godot error message is not gonna help in this case.
You need to figure out the reason how to build or why it doesnt build. How? Im glad you asked.
But first Ill let you know that vscode usually requires manual setup for things to work how you want them to work. (So I recommend Visual Studio instead for beginners)

  1. In vscode, press CTRL + P to bring up the command palette. Type in > sign. (You can alternatively press F1 instead and it will bring up the command palette but with the > sign pre-typed.)
  2. Type in Run task and select it
  3. search for a task named "build" or similar by typing in "build"
    => If something that looks correct shows up, select it. It will open a terminal which shows the build progress and prompt you an error message if it failed, or a success message.

I doubt that your vscode is correctly set up, so you probably wont see that selectable task. You now have 3 options

  1. learn how to setup vscode
  2. use VisualStudio instead and simply press CTRL + SHIFT + B to build the project
  3. open any terminal/console, use cd to change the directory until you are in your gemcatcher project and type in dotnet build to build from the command line. It might ask you for the project name in that case type dotnet build --project gemcatcher or whatever you have named your project

Once you have the build error, you will be highly likely to find the solution you need yourself.

  • Why I think your code doesnt build: Because Area2D is blue. Blue is usually used for variables. Classes are Green, see Paddle. Area2D is a class.
  • Why I think your vscode is not set up correctly?: You said your a beginner, and your syntax highlithing doesnt "look trustworhty" because the colors says something is wrong, but there are no red squiggly lines indicating an error. so only basic syntax highlighting is working but not intellisense