- Home /
Is there a way to save my project?
I was making my first unity project using this tutorial: I had a problem similar to this one: https://forum.unity.com/threads/general-problem-with-scripts-the-associated-script-cannot-be-loaded.185994/ And this one: https://answers.unity.com/questions/479572/the-namespace-global-already-contains-a-definition.html And this one: https://forum.unity.com/threads/the-script-needs-to-derive-from-monobehavior.568876/
The all three of these I tried to fix by making new script files and names for each script and it "fixed" everything but now I have a problem where it asks me to first fix the compile error but no compile error shows up when compiling (I'm using sublime text 3 and it normally shows me all the errors). This has gotten to the point where this:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Main_Control : MonoBehaviour
{
}
Gives a compile error when trying to add it as a component. I have run out of ideas for how to fix this. I can send the project files if someone suggests how.
,
Answer by Ermiq · Dec 01, 2019 at 08:36 AM
I have this Fix compile errors that don't actually exist everytime when I change class names or class file names. While in VS Code it's all fine and no errors, Unity says there are errors. Unity shows the errors on the scripts in inspector and doesn't let to attach new scripts (which are old ones actually but with the names changed).
Usually I just remove broken scripts from gameObject in inspector, close VS Code, sometimes close Unity, then attach new scripts to gameObjects again. Don't know the exact algorithm though, just try and error method.
By the way, sometimes all that needed is just to rename the class file name to the same name as the class after it has changed.
P.S., even with this issue, Unity is still way more forgiving and easy to fix than UE4, renaming or deleting classes and files in UE4 is a real nightmare and you can easily just lose the whole project because UE4 editor won't load at all if something like this happens, you can't fix the compile errors in IDE because in IDE it all compiles just fine, but UE4 just doesn't load and throws `Fix compile errors' immediately.
Answer by oTaijjo · Dec 01, 2019 at 08:49 AM
As @Ermiq suggested. I also would check, if the .cs file has the same name as the class. Unity needs those things to match, i.e. If your class is called MyClass then the script file should be named MyClass.cs.
If that doesn't help. Deleting the library folder, which will cause the whole project to be reimported, fixes nearly 90% of all my unexplainable issues.
Answer by pantang · Dec 01, 2019 at 06:17 AM
Do you have another script with "public class Main_Control : MonoBehaviour" in the file as these need to be unique to the file.
you can easily manage projects with unity hub if you are starting different ones.
Answer by infiniteWin · Dec 01, 2019 at 12:06 PM
Thank you for both of your replies but sublime text usually shows me errors and it doesn't explain why new scripts which I haven't modified are affected
Your answer
Follow this Question
Related Questions
Draw Calls increased after I upgraded to 4.0 1 Answer
Unity 4 drag and drop no longer works? 1 Answer
Three ingame buttons conflict with each other on iOS 0 Answers
Why does my trigger-collider receive Enter but not Stay or Exit? 1 Answer
Edit font texture (unity 4) for adding special effects. 2 Answers