Because the script class cannot be found. Make sure that there are no compile errors and that the file name and class name match
I have 100% made sure the names match. I never changed the names to begin with. I can not resolve this to add scripts to anything inside unity. Please help.
So, the script name matches exactly? And not something like PlayerManager and playerManager?
The script inherits from Monobehaviour?
And you’re not seeing any compile errors in the console? (this is possibly your issue if you can’t add any scripts to gameobjects)
You need to fix any compile errors in your code before Unity can compile any changes to code (or new scripts) that have been made. Unity has to have compiled your scripts before it will be able to add them as components of GameObjects.
No errors in console. File name and class match. I’m trying to get my son started on creating his first game in Unity, he’s 11. I made a simple controller for his character and it’s named “PlayerMovement” class is “PlayerMovement” as well. I’ve tried renaming, restarting, recreating the controller entirely. Nothing seems to be working. This only started after the new update. I even uninstalled and reinstalled Unity. I really don’t know what else to do.
This is the new controller I just started again. I’m trying to show him how to test as he goes and what all this means. But as I try to attach it to his character I get the error. Nothing in console. Names match.
I’ve just never had this issue in the past and I feel like it’s something simple that I’m missing. And I know I’ll feel like an idiot when I find it, but man I’ve been at this for days now.
Make sure the script is not located in a folder called Editor.
Copy the script physically away to another part of your hard drive, DELETE the copy in the project, then make a fresh blank PlayerMovement.cs script. If you can’t add that then the problem is somewhere else.
There’s no console errors. Though I’m leaning toward the issue being with PC, I haven’t had this problem with MAC. May be an issue with my desktop in particular, I don’t know. But I’m giving up. Thanks for the input.
One thing to try is export your assets as a unitypackage. Than start a new project and import the assets.
I know it sounds strange, but once we had an animation that no matter what we did was screwed up. Luckily it was a small project so I exported the scene, started a new project and suddenly there were no animation issues.
In Unity where your project is located (outside of Unity!) there are the Assets and the ProjectSettings folders… Library is right alongside, and PackageCache is underneath Library.
If anyone still has this issue you might want to try:
Go to the “Window” menu
Then down to “Package Manager” and click
You will get a list of every package available. Change from all available to just in project to shorten the list
Next click on the “package manager UI” from the list
Finally click “remove” from the lower right corner
Idk what is wrong but it still doesn’t work. Am i this stupid or is it just Unity? im literally trying to fix it for like 2 hours now and it is stil not working. Maybe my Visual Studio needs to be on the same disk as Unity or something but im going to stop trying…
This didnt work for me too(for Netcode simple example from Manual). I did this actually : i saved first wrong name of the script and opened it in vs 2019. Then i Renamed it in the editor(and again opened it in vs 2019) and it didnt work. Then i deleted C# script and created new one renamed it and then it all worked good. Basically it seems if it is renamed 2 times somehow system cannot find the file dont know why - bug probably.
So just create file rename it as u want and then open in vs 2019 and it works for me - i use latest .net, windows 10 => also both unity and projects are on the same disk etc though do not know is that related(other posters above wrote about this) - hope this helps