Hello, im new to unity and was trying to add a script to my game object when all it showed was this error: The associated script cannot be loaded, please fix any compile errors and assign a valid script. Every single time. to every new project.
Dont know what to do.
Any help would be much appreciated.
Im using Unity version 2021.3.22f1
And Visual Studio Code
Thank you
The steps to fix this problem are:
- Fix any and all compile errors in your project. You can see compile errors in the console window in Unity.
- Make sure your script’s class derives from MonoBehaviour
- Make sure your script’s class name matches the filename. E.g.
public class PlayerMovement should only appear in a file named “PlayerMovement.cs”
Everything is as you say. Let me make a quick demonstration video maybe that will help.
https://vimeo.com/815675651
The name of the class must match the name of the file. Unity is trying to find a class called “Controller” from that file and getting confused.
Rename the file and it’ll work.
1 Like
i feel very stupid right now. thank you for the help!
It’s certainly confusing! Before I realized what you had done wrong, I was struggling to remember exactly what weird context I’d seen this in before.
Yeah uuuh… how the F, i do that?
You need to open the console window in Unity to see your compile errors. Fix all compile errors.
Then follow the remaining steps as mentioned in my previous comment.
If you have some specific compile errors you can’t figure out, feel free to make your own thread.