Using Visual Studio Code with Unreal Engine

I would like to use Visual Studio Code on Mac to write my game code.
VSCode offers a C++ extension to add auto-complete and other features to the editor. To achieve that, you have to actually add your include paths to a c_cpp_properties.json file with a structure like this:

{
    "configurations": [
        {
            "name": "Mac",
            "includePath": [
                "/usr/include",
                "/usr/local/include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Linux",
            "includePath": [
                "/usr/include",
                "/usr/local/include"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        },
        {
            "name": "Win32",
            "includePath": [
                "C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/include/*"
            ],
            "browse": {
                "limitSymbolsToIncludedHeaders": true,
                "databaseFilename": ""
            }
        }
    ]
}

I guess I’d have to add the engine’s headers path to configurations.includePath, but it looks like adding “/Users/Shared/Epic Games/UE_4.15/Engine/Source” isn’t of much use.
Has anyone else tried to achieve this and managed to get autocompletion and sources navigation to work?

Cheers!

I’m also quite interested in utilizing VSCode in Unreal so that I don’t have to pay for a VS license myself…

Have you had any success with this thus far?

Yes, I’m currently using VSCode together with the awesome YouCompleteMe extension. It’s not exactly simple to setup but once you get it running it’s awesome. BTW VS community edition is free. I’m stuck with VSCode because I’m working on macOS.

Okay great. I’ll probably install VS Community Edition, then. Thanks for the response.

I tried getting YouCompleteMe to work with vim and UE4 but couldn’t get it working quite right. Would you be willing to share how you got it working and maybe what your config files look like :slight_smile:

Thanks ill see if I can make it work.

Is there a follow up in this? @tanis2000 Can you share something?

I’ve added those lines to my c_cpp_properties.json file:

                    "${workspaceRoot}/Intermediate",
                    "C:/Program Files/Epic Games/UE_4.16/Engine/Source/Runtime/",
                    "C:/Program Files/Epic Games/UE_4.16/Engine/Intermediate/Build/Win64/UE4Editor/Inc/Engine",

here is the full file: UE4 c_cpp_properties.json - Pastebin.com

IDK yet how to build from VSCode. If you know some way to launch UBT from vscode, this is the cmd to compile(source):

\UnrealEngine\Engine\Build\BatchFiles\Build.bat ProjectNameEditor Win64 Debug "X:\Path\To\The\Project\ProjectName.uproject" -waitmutex

You have to add a build task in vscode to be able to compile.
Here is my tasks.json:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Build Development Editor Win64",
            "command": "${config:UE4_Root}/Build/BatchFiles/Build.bat",
            "type": "shell",
            "args": [
                "${workspaceRootFolderName}Editor",
                "Win64",
                "Development",
                "\"${workspaceRoot}\\${workspaceRootFolderName}.uproject\"",
                "-waitmutex"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "pattern": {
                    "regexp": "^(.*)\\((\\d*)\\): (\\w*) (.*)$",
                    "file": 1,
                    "line": 2,
                    "severity": 3,
                    "message": 4,
                    "column": 0
                }
            }
        },
        {
            "taskName": "Regenerate Project Files",
            "command": "${config:UE4_Root}/Binaries/DotNET/UnrealBuildTool.exe",
            "type": "shell",
            "args": [
                "-projectfiles",
                "-project=\"${workspaceRoot}\\${workspaceRootFolderName}.uproject\"",
                "-game",
                "-rocket",
                "-progress"
            ],
            "problemMatcher": []
        }
    ]
}

(Had to split my comment in two…)

Be sure to configure the integrated shell to use cmd (under windows, of course ^^).
${workspaceRoot} and ${workspaceRootFolderName} are variables built in into vscode.
It will only work if you open your project folder directly under vscode, otherwise you can just put the absolute path.

I’ve added the config variable UE4_Root which points to the UE4 folder.
Just add “UE4_Root”: “C:/Unreal/UE_4.16/Engine” (with the correct path, of course) into your settings.json and you can use it with ${config:UE4_Root}.

You have 2 tasks defined here.
Building a Development Editor (Win64), and regenerating the visual studio project files.
This way I can manually add a .h into my project from vscode, regenerate it, and then build.
I tried adding a problem matcher, but it doesn’t seem to work tho…

I wanted to create a vscode plugin to try and ease-up the build process under vscode. But I may need some help to make it work under Linux/OSX too, if anyone is interested ^^

I’m interested too about the proper configuration for auto-completion. I can’t make a working YouCompleteMe configuration, and adding the folders manually gives me too much auto-completion (like methods from other classes…).

So, I’ve found that I had to change some things of your task.json file or I’ll just get a few errors when executing the task. Unsure why (I’m not much familiar with VSCode on Windows nor Windows dev).

Here is my code:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Build Development Editor Win64",
            "command": "& '${config:UE4_Root}/Build/BatchFiles/Build.bat'",
            "type": "shell",
            "args": [
                "${workspaceRootFolderName}Editor",
                "Win64",
                "Development",
                "'${workspaceRoot}/${workspaceRootFolderName}.uproject'",
                "-waitmutex"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": {
                "pattern": {
                    "regexp": "^(.*)\\((\\d*)\\): (\\w*) (.*)$",
                    "file": 1,
                    "line": 2,
                    "severity": 3,
                    "message": 4,
                    "column": 0
                }
            }
        },
        {
            "taskName": "Regenerate Project Files",
            "command": "& '${config:UE4_Root}/Binaries/DotNET/UnrealBuildTool.exe'",
            "type": "shell",
            "args": [
                "-projectfiles",
                "-project='${workspaceRoot}/${workspaceRootFolderName}.uproject'",
                "-game",
                "-rocket",
                "-progress"
            ],
            "problemMatcher": []
        }
    ]
}

And here is my config:

"UE4_Root": "C:/Program Files/Epic Games/UE_4.15/Engine"

Btw, thanks for sharing this.

Friends , Thanks a lot fo this share!!!

My question is => can i build Ue4Editor in vs code or only with visual studio?

Thanks in advanced

If what you mean is to build the engine from source with VSCode, then no, that’s definitely not possible yet.

Sorry @tanis2000, but its possible if you install visual studio comunity too, open vs code and just run the task in vs code…

So, its possible to build the engine inside vs code.
I can run the eidtor from inside vs code too and hit breakpoints. amazing.

I realize that after my question post. but thanks in advanced for your anwser.

This must have been added in 4.18, I’ve never seen it working before. Good to know!

For me its one of the best aditions in the past months. Visual Studio code is very clean and powerfull.