Download

Safely removing unused C++ code/files

In the project I am working on, at one point I was required to add C++ code, but later decided to turn my code into a plugin. The old code files are sitting in my project’s Source folder, along with other files (I currently have no C++ being used in the project). How do I go about safely removing all unused code files in my project?

You need to do it from your source code editor, then clean and build, if you dont have closed UE, it will keep the dll/library withouth update in some way, so even that you delete cpp files, the classes inside UE will still be shown.

If you have source control, delete them from there too, but remember the clean and build from the source editor with UE4 closed.

I have found that the best solution is to.
Delete the files in question from file explorer, and then Re-Generate the Visual Studio Project files.
For good measures you can Delete the “Saved” and “Intermediate” folders along with old .sin file.
Before you generate.

Removing things from inside the IDE have at times had unexpected behavior afterwards.

WCode

I do it exactly as WCode said.

I have also found that sometimes I have to clear the .bin folder and regenerate the game dll file for the c++ classes to be properly removed from the editor.

I do exactly this, as soon as I delete the files from the Source folder I regenerate the project and do a rebuild. Works perfectly (Y)

I do what WCode suggests almost anytime the code base changes in what seems a significant way (rename class, delete class, git pull, etc). I also run this whenever the editor crashes while trying to run the game or visual studio gives weird error messages. I do it so often I have created a powershell script for it and am strongly considering setting up a hotkey for it in visual studio.

My powershell script (keep in mind that I had to add the folder containing UnrealBuildTool.exe to my system’s path variable):



$binaryFolder=".\Binaries"
$projectFile="<Path To My Project>\MyProject.uproject"

if (test-path $binaryFolder){
	remove-item -recurse $binaryFolder
}

if (test-path ".\Intermediate"){
	remove-item -recurse -path ".\Intermediate\*" -exclude @("ProjectFiles","UE4.*")
}

UnrealBuildTool.exe -projectfiles -project="$projectFile" -game -rocket -progress