Unreal C++ with Visual Studio Code

By November 2, 2018Development, Tutorial

In the spirit of show casing alternative ways of working with Unreal and C++ I wanted to share with you guys how to use Visual Studio Code as your primary IDE.

Visual Studio Code is a fairly lean IDE based on the Electron framework that was designed to tap into the market of Sublime, Atom, etc etc but it works just fine as a C++ editor.

Similar to my earlier post there are a few prerequisites you need to have available / installed to follow this tutorial:

  • Ensure that you either have Visual Studio Community 2017  installed or alternatively just the Visual Studio Build Tools as you need something to still compile the code.
    • Visual Studio Code will recognize what you have these packages installed and assign the correct compiler configurations
  • Unreal Engine 4.20.3
  • Visual Studio Code
  • Windows 10

Once you have these pieces installed, let’s move onto the Unreal Editor configuration

  • Open Unreal Editor ( source or binary doesn’t matter )
  • Go to Edit -> Editor Preferences

  • Then go to General -> Source Code -> Source Code Editor and select Visual Studio Code

  • Once this is done you should now be able to generate a new Visual Studio Code project  using File -> Generate Visual Studio Code Project

  • This generation step will take a few seconds to complete
  • To open up Visual Studio Code go to File -> Open Visual Studio Code

You should now be able to see the IDE getting launched from Unreal and your project available for compilation.

The only other thing you need to be aware of is how to get at the build targets.

To do so you can go to Terminal -> Run Build Task or simply hit CTRL + SHIFT + B

That’s it !

You are now setup to use Visual Studio Code.

 

 

Additional Information

The only other thing you may want to setup within Visual Studio Code are a number of plugins that assist with intellisense, auto complete, etc etc

Here is a list of plugins I currently have configured:

Deleting Visual Studio Code references and changing back to a different editor

In case you are not happy with Visual Studio Code and want to revert things back to use Visual Studio I recommend cleaning up the files the VS Code integration generated.

Specifically the following folders / files inside of your root project:


.vscode/
[PROJECTNAME].code-workspace

Once this is complete you simply follow the initial set of instructions but instead of picking VS Code just select Visual Studio 2015/2017. This should then give you the option to re-generate the Visual Studio project within Unreal Editor ( File -> Refresh / Generate Visual Studio Project )

17 Comments

  • Raja Akel says:

    Hello, i had a problem downloading Unreal engine 4
    When running it it immediately crashes with error 0xc000007b “Application stopped working”. That’s allit gives me. Any ideas on how to fix it?
    Thanks

  • Lucas says:

    Hi, were you able to step through engine code with your setup?

    For me, every time vscode tries to open an engine file I’ll get something like “Unable to open ”: File not found (file:///d:/build/++ue4/sync/engine/).”

    • admin says:

      Hmm I cannot say I have this problem. Are you opening visual studio code from the Unreal Editor ? Have you tried checking out if you have plugins that are conflicting maybe ? Do you perhaps need to install the various plugins ( c++ / unreal snippets ) ? Perhaps try regenerating the project files. Perhaps if you have any errors we can see what else can be done.

      If it helps I am running Unreal 4.20 and 4.21 both seem to work. While Visual Studio Code is version 1.28.2. Here is a quick screenshot of the Engine.h file for example. https://i.imgur.com/YtfsJ1O.png

  • Peter Turner says:

    Thanks for this post!
    Wanted to get back into Unreal and things have changed slightly since a few years ago so certainly saved me a lot of time to switch from Visual Studio to VSCode which is my current editor of choice for Golang/Python etc

    It’s good to good to see it so well integrated though I doubt I’d ever have imagined it could be possible like this without your help!

    Cheers from London

  • Gyuyoul says:

    Hi, Thanks for this post!
    I can setup project with visual studio code after reading this article. and Build is successful.
    But whenever I hit F5 key to debug, code always shows me this error, “ERROR: Missing precompiled manifest for ‘Launch’. This module was most likely not flagged for being included in a precompiled build – set ‘PrecompileForTargets = PrecompileTargetsType.Any;’ in Launch.build.cs to override.”.
    Can you give me an idea to solve this problem?

  • Aydan says:

    Whenever I try to open vscode from the editor I get an error message: “Solution not found.”
    I’ve rechecked the process and I didn’t miss anything, any debugging advice?

  • sdb says:

    sadly my GPU only support up to 4.17 otherwise it will encounter DX11 feature level 11 required..and at 4.17 no vscode option inside the drop down.

  • You could add how to add modules:

    just add them in the modules field of *.uproject file.

  • Robert says:

    HI friend,

    Sorry for posting on a fairly old article but I am running into some issues trying to set up Visual Studio Code on my unreal and was wondering if you have any insights.

    Windows 10 OS
    I configured it inside the editor and restarted after it needed to rebuild. I launched with open code but got the message it was “unable too open”.
    Interestingly enough I tried using Visual Studio by itself and it works fine for opening just does not seem to like Visual Studio Code! (I am on version 4.24.3 of unreal engine) any ideas? It looks like it generated the code-workspace file after I ran it, but just won’t open for some strange reason…

    Also, forgive my ignorance as I am fairly new to unreal. But what are the advantages to using Visual Studio Code over Visual Studio in unreal?

    • Wojtek says:

      Hmmm once you generate the project files for Visual Studio Code from within the Unreal Editor you should be able to “launch” VSC from within Unreal. If for some reason that process is not generating the required project files you may want to delete them and try again. While I have not seen this type of corruption to project files you never know. It’s fairly safe to re-do the process.

      The fact that you mention Visual Studio itself works that’s positive. Once you generate your project files you should see similar build and run options between Visual Studio and Visual Studio Code https://imgur.com/a/wrok9ut

      Regarding why use Visual Studio Code vs Visual Studio ? It’s a preference really. Some people like a quick IDE without a lot of flashy tools while others prefer the vanilla installation. At this point if you are just new to Unreal I would suggest stick to Visual Studio + Resharper C++ Plugin if you have a few bucks to throw at it as it will save you a fair bit of work when it comes to intellisense. Other than that I would say just work on learning the techniques and the language and as you develop your skills you will decide which IDE is best for you. Unreal runs on a few different platforms so you can experiment ( Xcode, Rider, CLion, etc )

      • Robert says:

        Thanks for the response! Good to know it isn’t too big of a difference. I kind of figured it would be just a faster load than VS itself. I’ll focus primarily on the niche of UE with C++ and worry about the rest later as you’ve suggested.

  • Jack says:

    Hey! Really enjoying being able to work with VSCode using UE4. Really makes my development environment much cleaner.

    My only question is, do you know how to generate project files for VSCode from outside the Editor? My team and I spend a lot of time rebuilding the engine and generating project files, but it’s always the default (Windows: VS / Mac: XCode). I can’t find any info on updating the GenerateProjectFiles script to generate a specific solution type.

    Any help appreciated, thanks!

    Jack

    • Wojtek says:

      Hi Jack,

      Unfortunately I have not messed around with the project generation batch files too much but it looks like they are available as part of the Engine source code. Specifically the following https://github.com/EpicGames/UnrealEngine/blob/release/Engine/Build/BatchFiles/GenerateProjectFiles.bat

      You could take a look and see if there is enough overrides to manage this. Alternatively you could catch the commands through the “generate project files” / “refresh project” operations in the editor and see where they go. The output engine logs should provide some of that insight.

      If you do happen to come across a solution would be curious to know ! Thanks

Leave a Reply