Unity Ignoring My Code

My code gets ignored after the dialogue box appeared then it reverts to the last compiled which was yesterday and all the codes I typed maybe around the past 8 hrs gets ignored? how to fix this

Fix what?

We can’t guess what this dialog box is nor what your code is or was, and what it means that your code “gets ignored”.

Did you check the console for compile errors?

I appreciate the reply Sir!

unfortunately that’s what I’m looking the compiling error but there’s none. What happened was there’s a dialogue box that suddenly pops off saying it crashes (I’m not sure). then I closed my pc to eat and the first thing I saw was the project I’m currently building was opened “1 day ago” but in reality I was coding for like 20 minutes ago. It felt like it reverts to some old compiled code and ignores the recent codes, but the recent codes (The one loosing or the functions are not recognized) was running smoothly without no errors before I ate. Hoping I made it clear in order for you to help me, because I’m just starting and it’s for my School Capstone Project.

++ The code in the Visual Studio is still complete but when I’m compiling the game that’s when the problem is present. there’s no error but some of the functions are not functioning just like awhile ago.

++ It accepts the new code I’m writing and it runs. but the code in the said Time Frame was completely ignored. It’s like jumping and skipping the codes written in the time frame.

++It’s like it’s April 17 3:00 pm before I ate and the code runs smoothly then the box appeared. When I opened unity hub to continue working (April 17 3:20 pm) it says the project I’m working was opened “Day ago” like the ones I’m opening was the compiled project in (April 16). It’s like reverted to some old compiled codes.

I saw Unity reverting Assets values like ScriptableObjects…etc because the Editor is responsible for saving changes to disk (Serialization), and it can crash before doing this. But for Scripts, they’re just text files and saving changes to disk is handled by the IDE (code editor), not Unity. Unity just detects the changes and recompile your code. Unless you’re modifying code you’re not supposed to (for example Packages code, which Unity resets it before each compilation) then I’d say it’s impossible to lose code after Unity crashes.

I also highly suggest to use source control (like Git).

1 Like

You probably meant Packages. Code under Assets/Plugins is writable, a package might be read-only with changes getting reverted.

1 Like

Yes I meant packages, Fixed it thank you.

1 Like

thanks for the reply Sir,

now what’s the best I can do? thanks for the suggestion

I really don’t know what happened and I can’t explain it without having access to your Unity project.

First can you confirm that if you open the scripts files in the code editor your code really disappeared? If so then unfortunately there’s really nothing you can do, it’s just a (hard) lesson for you to always use source control (or at least backup your code often).

If you still can see your code but the game behaves as the code isn’t there, then it could be some weird Unity glitch (although personally I never saw this happen). First thing to do is to backup your scripts and your project (in separate folders preferably) then we can try to help you fix it.

I’ve seen this happen occasionally. I imagine Unity has some previously-compiled version cached and somehow missed that the file was “dirty” and should have been recompiled. Usually if you right-click and “reimport” the script, that fixes it.

In this case, I suspect there’s more going on, though.

1 Like