- Home /
Other - after fixing the typo and the error still present the problem was solved by backing up the project and starting a new project, then dumping the backups files into the new project.
Newly created scripts cannot be referenced
Hi all, since yesterday I've been facing the issue that all newly created scripts cannot be referenced. I have made no change to Unity Version, I have made no change to the way I create the Scripts though no matter what, every script created from yesterday onwards cannot be referenced by my project, the errors are both present in VS 2019-16.8.2 and Unity 2019.4.16f1- I have provided some screen shots below to show what is going wrong.
As you can see with this first one, one of my very first scripts for the project was to pickup objetcs, that is being referenced without issues to determine weather the correct item is being collided with, though the script I created yesterday to handle a Hydrocloric Acid item to store its data like remaining amount, ect. can not be referenced at all.
What would generally be a cause of this problem?
EDIT: After fixing the hilariously obvious spelling mistake I was still receiving the ORIGINAL error (the only reason the file was misnamed as I was trying to back track all the new scripts that werent working) I had renamed it in hopes to fix the previous problem, but all it sturred up was people more than willing to fix the incorrect script name, yet completly ignoring the original issue of all my last 5-7 scripts not being referenced by unity within Visual Studio, this was not due to an incorrectly named script, as I was receiving this error before I renamed any script. My fix was to backup the Assets and Project Settings Files, and import them into a fresh project, after that all the new scripts started getting refernced and would allow for auto completion ect. Also yes I tried the basics of restarting Unity and restarting my computer a handful of times before coming to doing a backup recovery
Answer by RodrigoAbreu · Feb 11, 2021 at 03:37 AM
@FuryFight3r, it happens when we name the class file differently from the class name.
In your case, the class is called hyrdoAcid and your file is called hydroAcid.
Also for code convention, name both with a capital H. So both class and file should be named HydroAcid.
Ah I see, though I only renamed the file due to this error beco$$anonymous$$g preset with every new script I create, it didnt matter if I right click in the 'Project' section of unity and Create C# Script, or if I add and create a script directly onto the GameObject itself, I was still presented with the same error, I can understand the confusion though thats my bad.
I had a Similar issue to this about a year ago, where every single script in my project couldnt be referenced, and the only way I could fix it was to Backup the Assets and Project Settings folders, create a new project and move the backed up files into the new project.. I just tried this with this instance and it worked with not only my Incorrectly Named script (after fixing the typo), but the 5+ other new scripts (peroxideScript, beakerScript, pumpSwitchScript, ect) that were also not working.
So I see that some of your scripts have the name "Script" in their file names. Are all the classes with exactly those same names? Capital also counts.
Im not sure what you mean, do you mean are they spelt exactly the same for both the file name and the Class Name? if so then yes, they are the exact same down to the capitalization.
Answer by Jaakk0S · Feb 11, 2021 at 02:41 AM
How about just put your hyrdoAcid [sic] class into a file named hyrdoAcid.cs? ;)
Follow this Question
Related Questions
How do I make a list of references to a variable? 2 Answers
Weird problem with referencing game manager 1 Answer
I'm having problems with referencing other scripts. 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers