How to delete class?

UE 4.15.0

Wow, I feel dumb…

I have just added a class derived from gamemodebase for my gamemode. Oops! UE4 already created one when I made the project, so I want to delete it… delete it… hmmm How do I delete it? It will not delete???

How do I delete a game mode derived class that I just added in the UE4 Editor?

1 Like
  1. Close Visual Studio and Editor both.

go to Source folder in your project folder.
ex)D:_Project[YourProjectName]\Source[YourProjectName]

  1. Delete Header(h) and Source(cpp) file. what you want to delete.

  2. Open Visual Studio and build.

  3. Open editor.

this will be working.
or, try this.

  1. Delete Intermediate folder.

  2. right click on Unreal Engine Project File.

  3. Click “Generate Visual Studio Project File”.

  4. Open Visual Studio and rebuild.

2 Likes

Seriously?? That is the process just to do something as simple as removing a class??

All you need to do is delete the files in Explorer, just like any other file. UBT will scan for any file/folder changes everytime it runs, and will invoke UHT to create/remove any required generated.h files.

If you have source control (which you should) and the files are already part of your repository, you can sometimes just Right-Click and ‘Remove’ them in the Solution Explorer. This depends on the Source Control extension you are using, but it should delete the file too.

To be honest there should rarely be a need to regenerate all your files unless something goes really wrong, or unless you just want a ‘Clean’ build. Sometimes however, if you are making a lot of changes to folder structure or renaming files, it’s easier to just do all of that in Explorer then regenerate the solution file so you don’t have to mess around with the filters.

This goes without saying, but the editor should not be open when you remove classes.

1 Like

Hopefully UE5 will have an option to delete a class through the editor simply by clicking a button or something like that. For now, I just add a comment to any classes I want deleted and remove them in batches to save time.

I must be doing something wrong…

  1. I closed VS and the UE4 editor.
  2. I deleted two classes (.h and .cpp) in explorer.
  3. I deleted the intermediate directory.
  4. I regenerated the VS project files.
  5. I opened VS and waited 5 minutes for it to compile successfully.
  6. I opened the UE4 editor.

deleted.png<— Undead Zombie.

Both classes still show up in the UE4 editor. There are no options to delete it. I restarted, regenerated, and rebuilt one more time for good luck. The zombies were still angry.

So then…

  1. I closed VS and UE4 editor.
  2. I deleted the intermediate directory.
  3. I deleted the binaries directory.
  4. I deleted the build directory.
  5. I regenerated the VS project files.
  6. I recompiled with VS… (elevator music)
  7. I opened the UE4 editor.

The zombies are dead! Apparently the double-tap shotgun just ■■■■■■ them off. I had to go nuclear and delete the build+binaries directory as well.

Crossing my fingers for UE5 getting some zombie kung-fu like Unity’s one-step-zombie kill…

1 Like

In the first example you didn’t delete the binaries folder. The binaries folder is where the compiled .exe of your project is. Opening the project therefore wouldn’t have done anything because the development binaries are still there - if you double-click the project file while a development .exe exists in the binaries folder it will not check whether it’s up-to-date or not.

Also critical here is that’s only only the development exe. If you open VS and build a ‘DebugGame Editor’ exe, but open the project outside of VS, it will still use the Development Editor exe.

If you delete from explorer then build in visual studio it will detect the removed files and rebuild. If you delete a C++ class you must recompile the exe, and by extension restart the editor. There is no getting around that.

If you like, you can create a batch file/powershell script with the following code and place it in your project folder. I call it ‘Clean.bat’

I use this regularly if I want to do a completely clean build, and it’s a bit safer than hitting “Rebuild” in VS and triggering a full engine build too.



echo 'Cleaning'
powershell.exe -NoExit -ExecutionPolicy -Bypass -Command "ls -Recurse -Include Build, Intermediate, Binaries, Saved, .vs -Exclude Saved/Config/Windows | rmdir -Force -Recurse"


3 Likes

Is there a reason, a lot of minor QoL features for cpp devs never got added?
Deleting classes, renaming classes, moving objects between folders not being slow and buggy due to how redirectors work.

I don’t get how the engine has been in development for so long and basic **** like this wasn’t added to the editor.

4 Likes

It doesn’t seem like there’s an easy way to do this, but this worked for me when the above didn’t:

  • Close UE and VS
  • Navigate in file browser to your game’s root directory
  • Search for YourFileNameToDelete
  • Delete every file with that name
  • Delete Binaries/
  • Open VS and recompile
3 Likes

Thanks, this worked for me!