Skip to content

Instantly share code, notes, and snippets.

@th3terrorist
Forked from chillpert/vim-unreal.md
Last active July 30, 2022 11:33
Show Gist options
  • Save th3terrorist/f0631d5c1835c1f7fc5749205198384f to your computer and use it in GitHub Desktop.
Save th3terrorist/f0631d5c1835c1f7fc5749205198384f to your computer and use it in GitHub Desktop.
Debugging and autocompletion for Unreal Engine 4 projects in (Neo)Vim

Debugging and autocompletion for Unreal Engine 4 projects in (Neo)Vim

Autocompletion

  1. Install coc.vim, e.g. with vim-plug inside .vimrc:
    Plug 'neoclide/coc.nvim'
  2. Run
    :CocInstall coc-clangd
  3. In UE4Editor
    • go to Edit - Editor Preferences - General - Source Code - Source Code Editor and select Visual Studio Code
    • go to File - Refresh Visual Studio Code Project
  4. Create a symlink from your project's root directory to myProject/.vscode/compileCommands_myProject.json
    ln -s .vscode/compileCommands_myProject.json compile_commands.json

Alternatively, you can also use YCM or Neovim's native LSP.

Debugging

  1. Install vimspector, e.g. Plug 'puremourning/vimspector'
  2. Configure debugging vimspector keybinds or simply add let g:vimspector_enable_mappings = 'HUMAN' to your .vimrc.
  3. Create a .vimspector.json inside of your project's root directory (simply refer to the myProjectEditor (DebugGame) entry in myProject/.vscode/launch.json), e.g.
{
  "configurations": {
    "Launch": {
      "adapter": "vscode-cpptools",
      "configuration": {
        "request": "launch",
        "program": "/path/to/UnrealEngine/Engine/Binaries/Linux/UE4Editor-Linux-DebugGame",
        "args": [ "/path/to/myProject/myProject.uproject" ],
        "cwd": "/path/to/UnrealEngine",
        "externalConsole": true,
        "MIDebuggerPath": "/usr/bin/gdb",
        "MIMode": "gdb"
      }
    }
  }
}
  1. Compile a debug build path/to/UnrealEngine/Engine/Build/BatchFiles/Linux/Build.sh myProject Linux DebugGame '/path/to/myProject/myProject.uproject' -waitmutex
  2. Set a breakpoint (F9) and start debugging (F5) in Vim and your project will open in a new instance for debugging.

If you just wish to compile your project refer to the following entries in myProject/.vscode/tasks.json: path/to/UnrealEngine/Engine/Build/BatchFiles/Linux/Build.sh myProject Linux Development '/path/to/myProject/myProject.uproject' -waitmutex For anything else building and debugging-related simply refer to tasks.json and launch.json in myProject/.vscode.

ue4-cli

I highly recommend using ue4-cli. This application is primarily used for compiling your project from the terminal but it can do a bunch of other neat things like running automation tests, generating IDE project files, cleaning your build files, and even packaging your build. It also works for UE5 if you set the engine path manually (at the time of writing, this is still a bug). I defined a function in my .zshrc to act as a wrapper for ue4-cli which adds all of the automation that I like to have in my workflow.

UE5

When trying out this setup for UE5, I was greeted with plenty of clang errors. I was able to get an experience that is on par with vscode by modifying my compile_commands.json. Instead of using the clang binary that ships with Unreal Engine, I would use my own clang++ (13.0.1) by simply removing the full path to UE's clang from each value in the file. Then I added -ferror-limit=0 right after clang++. Finally, I had to use C++20 (even though it is not supported by UE) to get rid of bad member function call errors.

{
	"file": "/home/User/MyGame/Plugins/UEGitPlugin/Source/GitSourceControl/Private/GitSourceControlMenu.cpp",
	"command": "clang++ -ferror-limit=0 -std=c++20 /home/User/MyGame/Plugins/UEGitPlugin/Source/GitSourceControl/Private/GitSourceControlMenu.cpp @/home/User/MyGame/.vscode/compileCommands_MyGame/GitSourceControl.4.rsp",
	"directory": "/home/User/unrealengine/Engine/Source"
},

Troubleshooting

If coc is telling you that clangd is missing input files, try the following:

  1. Inside of your compile_commands.json locate the file key of an entry and copy its value (the total path of the file)
  2. Locate the command key of the corresponding entry and insert the value right after the path to clang++ and before the path to the .rsp file
  3. Repeat for each entry in compile_commands.json

To verify that it is working try to run the command in a terminal. It should start compiling (don't expect it to finish without errors though). You might want to automate this procedure, especially if your project contains a lot of files. If requested, I can share the tool I quickly put together.

Also, if you are on Arch and experience long loading times when starting the editor follow the instructions on the Arch Wiki. It really makes a difference.

Tested on

OS - Arch Linux
VIM - Vi IMproved 8.2
NVIM - 0.6.1
coc.nvim - 0.0.80
clangd - 12.0.1
Unreal - 4.27

Tested on

OS - Windows MSYS
VIM - Vi IMproved 8.2
NVIM - 0.6.1
Unreal - 4.27

Rhighs: On Windows it was too slugghish and indexing took a ton of time more in big proejcts compared to what I've experienced on Arch Linux. At the end I surrendered to the evil of MS Visual Studio + VSVim extension.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment