How to delete a created C++ class?

I have a misstake that is create a wrong C++ class , that name is “MyActor” in the content browser,
so how can I delete it?

With the editor closed. Goto the project’s path on disk, so for me it’s

C:\Users\Rah\Perforce\Workspace\MyExampleProject
then direct yourself into your source folder and into your projects name so for me it’s MyExampleProject folder
C:\Users\Rah\Perforce\Workspace\MyExampleProject\Source\MyExampleProject

look for your files in this folder directory, they will have either been created in the private and public folders by default.
Or they will be in whatever folder you specified when you created the files. Delete both the DesiredClass.h and DesiredClass.cpp from disk.

C:\Users\Rah\Perforce\Workspace\MyExampleProject\Source\MyExampleProject\Private

and

C:\Users\Rah\Perforce\Workspace\MyExampleProject\Source\MyExampleProject\Public

maybe

C:\Users\Rah\Perforce\Workspace\MyExampleProject\Source\MyExampleProject\Custom

Direct yourself back to the projects root

C:\Users\Rah\Perforce\Workspace\MyExampleProject

RightClick on your .UPROJECT and Generate Visual Studio Files.
Rebuild and you are done!

Is this really the proper solution for removing classes? Anything that involves a user to go into the project folder and physically remove files from it seems at least weird. What if you have a lot of classes to delete, wouldn’t it be too convoluted to seek them all in folders you mentioned?

If you are able to create classes inside the engine you should also be able to remove them the same way.

You have to do it manually unfortunately.

UE 4.13 OSX example removing MyActor class from hello_world project

  1. Close editor
  2. Remove MyActor.cpp MyActor.h
  3. Double click hello_world.uproject to launch editor
  4. Compile in editor
  5. Restart editor

Just ran into this myself. It’s kind of a joke really. The reason they won’t allow people to delete classes from the editor is because they don’t have a good way to detect where that class is being used. This is not their problem though and if it was then they should be working to figure out a way to be able to do it. Honestly its the responsibility of the person and team working on the project to keep track of where they used a class and fix them when they make a decision to delete a class and that’s if it was even a class they were using. For me it was one class that wasn’t used by anything and yet I still had to follow these steps. A simple warning when attempting to delete a class would suffice for any liability to someone ruining their project this way.,

Maybe an option like “delete unused classes” would suffice

A simple “Delete” would be nice.

1 Like

You don’t have to generate project files as SaxonRah mentioned.

All you need to do is go to the project folder then there should be a Source folder with your project name inside it.
Click on it and you should see the .h and .cpp file of your script. Remove these, compile in the editor and restart.

Example: B:\My Projects\Unreal Projects\FPSGame\Source\FPSGame

For me I just delete the .cpp and .h file in computer and build in visual studio ,is build not rebuild.and it have been delete.

Please fix this Epic.

This is what I found too, delete the code, compile in the Editor (!!), restart inbetween to remove any dangling references. I have found the Editor will telll you it has a reference to a Blueprint that you may want to clean out (as a result of removing a C++ class) and you may have to restart to remove that reference.

This is what I found too, delete the code, compile in the Editor (!!), restart inbetween to remove any dangling references. I have found the Editor will telll you it has a reference to a Blueprint that you may want to clean out (as a result of removing a C++ class) and you may have to restart to remove that reference.