Visual Studio Code not working with UE

I have started using Unreal Engine and wanted to switch from VS 2017 to VSC because intellisense in VS is not very good
and often simply stop working.
I have set VSC to be the source code editor in UE and created a new Project called “MyProject”.
I also created a new C++ component called “NewActorComponent”.
I have installed all required plugins for VSC.
However there are a lot of errors in VSC:

When trying to start the debugger I got two seperate errors, depening on which depug mode is choose:
(Debug)
Error pop-up: "Builderror during preLaunchTask “MyProject Win64 Debug Build”
VSC terminal: ERROR: UBT ERROR: Failed to produce item […]MyProject-Win64-Debug.exe

(DebugGame)

In addition the terminal says the program exited with code 1 (see 2 pictures above).

Deleting the folders .vscode and Intermediate does not help.
In short: It’s impossible to work with VSC as the code editor with Unreal Engine.

Also: I have set VSC to be the DEFAULT source code editor (“Set as Default”) however, this is NOT SAVED when restarting the computer!

I have managed to eliminate some bugs:

  • When UE is generating a new project with VSC, it’s not adding the “/Intermediate/Build/Win64/UE4Editor/Inc/[Project name]” path to the c_cpp_properties.json file and also is not creating the .generated.h files. Only after compiling from the editor, those files are generated.
    Adding the path manually to the json file and compiling the projet from the editor once does solve the include bug.

  • In each headfile you have a macro between the class keyword and the class name, called [Project name]_API (in my case MYPROJECT_API). This macro is unnown to VSC so you need to add it to the intelliSenseMode section of the json file:

    “intelliSenseMode”: “msvc-x64”,
    “defines”: [
    “_DEBUG”,
    “UNICODE”,
    “MYPROJECT_API=”
    ],

I still have some bugs left:

  • In my created C++ class I have the error “incomplete type is not allowed” on the inherited UActorComponent class:

    class MYPROJECT_API UNewActorComponent : public UActorComponent

I also have errors on GENERATED_BODY(): “overloaded function “UClass” is not a type name”,
the function BeginPlay() and TickComponent(): “member function declared with ‘override’ does not override a base class member”.
Those bugs can be resolved when I inlcude Engine.h in the headerfile, but this is not and acceptable sollution, because this is not how it should work.

  • In the cpp file for that header file I have the error “#include errors detected. Please update your includePath. IntelliSense features for this translation unit (F:\Unreal\MyProject\Source\MyProject\NewActorComponent.cpp) will be provided by the Tag Parser.” for the #include “NewActorComponent.h”.

(I am not sure if either of these are the right answer)
Have you tried uninstalling both VS2017 and VSC and then reinstalling them?
Have you looked at this Plugin? ue4-cpptools - Visual Studio Marketplace

I have re-installed Windows recently (not because of that), so no, reinstalling both programms does not help.
That plugin is no longer in the VSC marketplace and also I can’t install it, because if I rename the zip file to .vsix I get an error when trying to install it.

I tried to post a reply in the Unreal Forum thread you started but its pending approval. Check this link for a fix, you just need to rebuild the unreal build tool.

https://github.com/EpicGames/UnrealEngine/pull/4476

1 Like

“Page not found”

Works fine for me, you need to have a GitHub account linked with your epic account to be able to see the UE4 Repo. Here is a link to guide you on getting that setup.

Oh ok, I wasn’t logged in -.-

I tried to open UnrealBuildTool.csproj with Visual Studio 2017, but when I build it, I get a ton of errors in the VSCodeProjectFileGenerator.cs file, mostly because this is a html document…

VSCodeProjectFileGenerator.cs is a C# source code file… You need to open/edit VSCodeProjectFileGenerator.cs in VS2017 to maintain its formatting. If you changed it with something like notepad and saved it you will lose the formatting and build errors will occur.

Posting errors or images would make it easier to help you.

Just tried it with a fresh source code build and it works perfect,

For some reason I didn’t download the changed file, but the webpage, no wonder the file consisted of html code only -.-
Now I could compile it and VS Code works now fine, thank you :slight_smile:
Can you post an answere here directly, so that I can mark it as solved? (You can’t do that with comments).
Unreal should implement that bug fix fast, so that VS Code works with Unreal.

Check this link for a fix, you just need to rebuild the unreal build tool after making the relevant changes to VSCodeProjectFileGenerator.cs (Github account is required to view the link, must also be liked with your unreal account, see Unreal Engine on GitHub - Unreal Engine for help with that if required)

https://github.com/EpicGames/UnrealEngine/pull/4476

Presumably the bug fix will be merged and included with the next update to the Unreal engine.

Glad you got it sorted, I have added an answer below to be marked as solved as requested.