Ok, wow.
I don’t know what’s going on but this is serious. I just opened a C++ class my Unreal project that I have been working on for days and it was empty! Both the .h and the .cpp file only contain the default header that they contain after creating a new C++ class in Unreal. If I didn’t have a backup from yesterday I would have lost everything! The weird thing is that the code is still being executed in the game, even after I recompile. How is that even possible? And what causes this?
This may be an issue with the IDE itself? What are you using? Most likely Visual Studio? I somehow doubt Unreal itself could’ve done this to your source code.
Also if you happen to be using source control, you might be able to restore things? If unreal is somehow compiling your code as if it’s actually there, it must be there somewhere hopefully? It could be something is cached in the Intermediate folder? I’d avoid doing any “clean” operations in the hopes of recovering the files in case they are cached somewhere.
I know something like Rider for Unreal which is built on IntelliJ has a file history option which may help you recover edits in the future if you decide to switch to that.
I am using Rider. I’ll try to find if there’s something saved in its history.
I don’t know if this is related but I also have this bug where my C++ classes only show up in the content browser after I compile and all the Blueprints derived from the class are broken. That’s why I tried regenerating the VS files and after that the class was empty.
With Rider, if you right click a tab, it should have the file history. It may be gone if you closed rider.
I’ve never seen this issue myself with regenerating VS files, and I hardly ever use the content browser to manage C++ classes. Hopefully it is in fact cached somewhere.
My workflow used to be really weird where I’d manually create C++ files through explorer, and then regenerate VS files. When I did it through Visual Studio, it actually created the files in the intermediate directory. Rider fixes that. And I didn’t always have Unreal open and running so I had to create my files that way.
Thank you for pointing me at the file history in Rider. It might come in handy if this happens again.
I’m still absolutely confused how this happened and scared that it might happen again.
I don’t understand how Unreal was still compiling the code even the it was completely deleted from the .h and .cpp files.
Edit: I can also see that moment when my file was reset to default in the Rider history. What’s odd is that the date of the file displayed in Rider is suddenly 3 days older in that one entry.
So weird. I feel like maybe it was a rider issue, and Unreal must have been compiling something in some intermediate directory cache.
Also, maybe since the source file date was 3 days older, the build didn’t detect that the object files needed to be recompiled. Pretty sure that’s how make files usually work, and something similar went on there. Maybe the OS somehow decided to set your files to their state from 3 days ago with something similar to apple time machine?
I don’t think it was the OS because as far as I know I don’t have that snapshot feature activated. I once wanted to reset a file to an older state and the file history was empty.
Where exactly does Unreal store those make files? Because I couldn’t find any scripts in any of the project folders other than the actual file of the script that I am working on.