Yesterday I renamed a class and a header file to something else and it completely destroyed my project. Errors everywhere and I had to pull a backup version and rebuild a few days worth of work. Which leads to my question of how to create, edit, rename, delete, move to a new folder. You know the typical file organization stuff.
Shouldn’t it be as simple as just moving stuff around? It always seems to wreck my projects. Am I missing a step that refreshed the code both in the editor and visual studio? Hitting the rebuild visual studio project from explorer doesn’t seem to do the trick either.
Whenever I have to move files or reorganize the directory structure, I delete the “.vs”, “Binaries”, “DerivedDataCache”, “Intermediate”, and “Saved” directories within my unreal project directory and THEN run “Generate Visual Studio Project Files” on the .uproject file.
Also, you’ll need to update the #include statements for any files that are reliant on your moved source files.
Failing to do either of these steps can result in errors.
If this doesn’t help, post the text of the errors you’re getting and we may be able to offer more help.
Hey, It should be enough to just delete your binaries and rebuild your project. Also if you delete code files they still might be in your folder as an actual file so it is best to check this also and modify accordingly.
That’s a good point.
“Removing” files from your project within Visual Studio doesn’t delete the actual source file from the directory, and the file will be detected and re-included in the future.
Further, dragging a file to a different filter within the Visual Studio hierarchy doesn’t actually move the file to a new directory. Renaming a file will rename the actual source file, but other disc operations aren’t one-to-one.
I tend to delete the DerivedDataCache because (as I understand it) that’s built by the UE editor when it’s run (if it doesn’t already exist) so if I’m regenerating the project files I know I don’t have any legacy effects that didn’t get rewritten.
I delete the Intermediate folder for similar reasons, but that’s the directory that’s actually created when you run “Generate Visual Studio Project Files”. When tracking down some build errors UE staff have recommended I delete the Intermediate directory. It seems like one of those things that “shouldn’t” matter, but sometimes does. It’s probably overkill on my part; I have a tendency to do that.
The Saved directory I clean up mostly to prevent large archives of unneeded log files from building up. I could do that whenever, but it’s just a habit I’ve developed whenever I’m fully rebuilding the project. Kind’ve a “might as well” action.
Should I also be able to rename files similarly? It could have been something I was missing, but I renamed a .cpp and a .h in visual studio and I never could get it resolved, not be removing those folders and rebuildings, not by modifying the include statements…nothing I had to restore from a backup version. What i’ve been doing since then is creating a new file, copying the code over and removing the old file. That seems to have worked but was a bit of a pain when I should have been able to just rename.
What it sounds like you’re describing should have worked, but I’m not certain I’m clear on exactly what you’re doing.
If you are leaving the files in the same directory and only renaming them, you should be able to do that in Visual Studio (right-click on the file and “Rename”).
If you are moving the files to a new location, even if you are keeping the same filename, you need to remove the file from your project (right-click, “Remove”), then move the file to the new directory, then add the existing file to your project (right-click on the target filter within the Visual Studio hierarchy, select “Add Existing Item”, and browse to your file(s) ).
At that point, I would close Visual Studio, delete the Intermediate, .vs and Binaries folders, Generate Project Files, open Visual Studio, allow Visual Studio to completely scan for all includes etc., then try your build. It should work.
You’re right, having to create a new file and copy code over just to rename a file without changing the directory is not okay.
If you have a problem like this in the future where you need to revert to a backup; rather than lose your work, you can move or copy your new code files to a directory outside your project. Then, after you revert to your backup project, just move the saved files into the proper directories within your project with the filenames you want. At that point use “Add Existing Item” from within Visual Studio and go from there. It’s still a bit of a pain as a workaround, but less troubling than what you’re describing.
Where is the DerivedDataCache? I don’t see it in the folder structure?
It’s created when you open your project in the UE4 editor. If you haven’t tried that it won’t exist yet.