Rename C++ File

Hi.

Just a quick question. Let’s say I have a file called MyClass.ccp and MyClass.h in the VS Solution. If I rename those files, Unreal Engine auto regenerate the project and I lose my changes…

what is the workflow to rename class files?

What do you mean you lose your changes? And what is auto-regenerate? Projects are generating when you change Engine version or choose Regenerate projects. Both operations are manual. Also, projects generator doesn’t touch source files. It just scans your Source folder and organize VS project files and solution file.

Are you renaming through Visual Studio?

For example:

  • I add code, lets say AItem.
  • I rename then in VS the code to AItem2 and all the includes and references

After that, Unreal Engine cannot compile anymore with an error of AItem not found.

Same happens if I try to remove AItem.cpp and AItem.h

You filename should match your UClass name. So if your rename your UClass from AItem to AItem2 you should rename your header and source files to Item2.h and Item2.cpp.

Here’s documentation for unreal code standards: https://docs.unrealengine.com/latest/INT/Programming/Development/CodingStandard/index.html

If you want rename .cpp/.h files in Visual Studio, just do it, they will become renamed on disk, not only in project.

If you want to remove files from Visual Studio project, you must do it outside of Visual Studio, manually, using Windows Explorer. Because if you remove files only in Visual Studio, they will not be deleted from disk and GenerateProjectFiles.bat will include that files to project again and again.

If you want add new files to Visual Studio project, best way to do this is to open your project in Unreal Editor and use Edit->AddCodeToProject.

Apart from what newbprofi said if you rename those files that contain UObjects (those that have a corresponding myclass.generated.h file) you have to re-generate the project files.

Ok Great, I needed to know all this workflow of: rename/ delete file, generate again the sln, compile it… and then reopen UE.

Thanks!