- Home /
Error when trying to add script to game object via editor.
Receiving the error "Can't add component 'PlayerController' because it doesn't exist. Check to see if the file name and class name match." when trying to drag a C# script onto a GameObject from the project browser, into the Scene editor. The filename and class name do indeed match. This even happens with brand new, empty scripts, seconds after creating them.
Tried in a different scene with a new gameobject. Same error.
Tried in a different PROJECT with new scripts and gameobjects. No error at all. Go back to the old project, error's back. Restarts, "Reimport All", did nothing to fix it.
I guess that's the fix, just to start a new project. I'd just like to know what I can do in the future to avoid breaking an entire project.
Sometimes this type of issue occurs if you move files from windows explorer which breaks internal linking in Unity. The remedy is to always move or rename your files from the project panel only.
$$anonymous$$ight be a corrupt library. If that's the problem, I hope you had backups.
Sometimes, issues along these lines can be fixed with "Sync $$anonymous$$onodevelop Project" (under the "Assets" menu).
Answer by b3ntl3ys · Aug 14, 2014 at 06:48 AM
I have found right clicking in the Project view and click refresh works sometimes
Answer by EternalAmbiguity · Dec 30, 2014 at 03:58 AM
I realize this is late, but because no one seems to have an answer, I'll say it:
I encountered this, and it seems to be because the actual file name of the script is different from the name following
public class ScriptName : MonoBehaviour
In the above, the part I've called "ScriptName" needs to be the same as the file name of the script for it to work.
Your answer
![](https://koobas.hobune.stream/wayback/20220613151726im_/https://answers.unity.com/themes/thub/images/avi.jpg)