Can't add code to project

Hey!

I have been learning using unreal game engine 4 and everything worked fine until today. When I encountered a problem.

When I create project in unreal engine using blank project setup with starter content (or any other project set up) I can’t add C++ classes to project. When I try (using the “Add Code to project” button in the editor) I get the following error in a window:

Failed to add class MyGameMode. Failed to generate project files.

And after I close the window it says the following above the selected name of the class:

The name MyGameMode is already used by another class.

Although it says it fails it still is able to create files MyGameMode.h and MyGameMode.cpp with default layouts
(they can be seen in the projects source directory).

I also tried to generate visual studio project files by going to the projects directory and selecting
“generate visual studio project files”. It results into following error:

Failed to generate project files

System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
System.IO.Path.InternalGetTempFileName(Boolean checkHost)
UnrealBuildTool.Utils.SetEnvironmentVariablesFromBatchFile(String BatchFileName)
UnrealBuildTool.VCEnvironment..ctor(CPPTargetPlatform InPlatform)
UnrealBuildTool.VCToolChain.GetVCIncludePaths(CPPTargetPlatform Platform)
UnrealBuildTool.VCProjectFile.WriteProjectFile(List`1 InPlatforms, List`1 InConfigurations)
UnrealBuildTool.ProjectFileGenerator.WriteProjectFiles()
UnrealBuildTool.ProjectFileGenerator.GenerateProjectFiles(String[] Arguments, Boolean& bSuccess)
UnrealBuildTool.UnrealBuildTool.GenerateProjectFiles(ProjectFileGenerator Generator, String[] Arguments)
UnrealBuildTool.UnrealBuildTool.Main(String[] Arguments)

Few days ago I was able to add code to my project by simply using the editors “Add code to project” button. I haven’t changed anything that I know of. I looked for answers and found out that few others had had the same problem but I didn’t find a solution from those posts.

I’m using a Unreal Game Engine 4 version 4.7.2 (I also tried installing previous versions
and experienced the same problem) on Windows 8.
I have Visual Studio Desktop Express 2013.

All help will be highly appreciated!

Try Visual Studio COmmunity Edition: Visual Studio 2017 15.9 Release Notes | Microsoft Learn

if mikepurvis 's answer didn’t help, you can try to regenerate your project (if it’s just one project that is having issues)

like this:

and if that doesn’t help or if it’s any project you make, might want to uninstall/reinstall UE4(not just the version). I had to do that a few weeks ago

Thank you for your answers spazchicken and mikepurvis. I reinstalled unreal game engine and installed Visual Studio 2013 Community edition but I still get the same error message when I try to add code to project (and this is to any project which I create).

I did some more googleing and finally found the answer! Here is the link to the solution that worked for me: [4.7] UnrealBuildTool Failed to generate project files - C++ - Unreal Engine Forums

So it worked after I cleaned the contents of the AppData/local/Temp folder. Folder can be found at least in windows 8 by pressing windows button + R and typing %TMP%. AppData folder should be in Users//AppData but it migth not show up in the file explorer. I didn’t remove everything in that folder but instead every time I got warning from the OS that the file was important I pressed skip. After removing files I got blank screen but after restarting everything worked fine (so might be a bit risky at least don’t delete all files in temp) including adding code using unreal editor and generating visual studio files. I also read that using software like CCleaner could fix the problem maybe more safely.

Hope this helps if someone has the same problem.

I take you didn’t solve the problem then? I’ve got the same issues and opened a thread in the forums but haven’t been able to get it working. The solution with the Temp folder didn’t work for me.

Cleaning the temp folder worked for me. Have you tried to reinstall visual studio? Do you also get the error (error in the original question) when trying to generate visual studio project files for your project? Did you start the new project after cleaning the temp since otherwise it still contains the old headers c++ wizard created?

I’ve done everything you say plus some. I don’t get the error trying to generate the project files. However I do get the same behavior you describe in the first half of your question. However, I can’t compile the solution because the headers for the “falsely” added classes are invariably reported as “not found” by the compiler (WidgetBlueprint.h, in my case). I’ve opened a thread in the forum, maybe you know of something: Can't add code that inherits from classes other than Actor - C++ - Unreal Engine Forums