DEV Community

Cover image for Unreal Engine with Neovim: Config for Game Development
Rodney Lab
Rodney Lab

Posted on • Originally published at rodneylab.com

Unreal Engine with Neovim: Config for Game Development

🧑🏽‍💻 Why use Neovim with Unreal Engine?

In this post, we see how you can work in Unreal Engine with Neovim for game development. Unreal Engine lets you define game logic using Blueprints (a codeless Visual Scripting UI) or C++. We focus on C++ in this post. The solution has been tested on macOS, but might also run just fine on Linux, and possibly Windows. Please let me know either way how you fared, if you tried those alternatives.

Officially, Unreal Engine does not support Neovim. That said, you might still prefer to opt for a lightweight text Neovim editor, like Neovide, which has a small memory footprint — useful when you have a resource-intensive game open, in the background in the Unreal Engine Editor. Neovide, written in Rust, is a no-nonsense, cross-platform Neovim GUI. Of course, it supports code code completions, quick fixes and other features you will expect from a modern editor.

If you are just looking to use Vim movements to make your editing more efficient, there is another alternative. You might consider using CLion or VS Code as your editor, and adding a Vim plugin that will let you use those Vim movements. This post targets readers who are already familiar with Neovim, LSP and setting up plugins, though there are links included for guides, which might be helpful for anyone not yet comfortable configuring Neovim.

⚙️ Installing Xcode for Unreal Engine on macOS

Even though we do not use Xcode as the editor here, you will need Xcode installed on your system for compiling the under the hood. Be sure to check the Unreal Engine Xcode requirements for your Unreal Engine version you are using, and install the Xcode version listed as being supported. As an example, I was able to compile code successfully using Xcode 15, but when I tried to re-open the project in Unreal Engine, I got a “The following modules are missing or built with a different engine version” error below (even after rebuilding).

Unreal Engine with Neovim: Screenshot shows Unreal Engine Editor error dialogue advising "The following modules are missing or built with a different engine version".

However, by downgrading to Xcode 14.3, I got everything to run smoothly. You can download the latest version of Xcode from the macOS App Store, using a shortcut already on your dock or Launchpad. However, if you require an older version, you will need to use the Apple Developer site to download Xcode, logging in and completing any two-factor authorization requests. I would recommend using Safari for the download; the file will be quite big and Safari supports resuming your download, in case the connection drops.

You can have Unreal Engine generate the necessary VS Code project configuration by setting VS Code as your editor, then opening VS Code from the menu in Unreal Engine.

🧱 Running Unreal Engine builds in VS Code

With Xcode and Unreal Engine set up, let’s have a look at how to run builds from VS Code. To build your Unreal project using VS Code, install the C/C++ VS Code extension from Microsoft.

Unreal Engine with Neovim: Scrren capture shows the C/C++ extension by Microsoft preview in the V S Code extensions view.  Current version is v.1.18.5 and there have been around 59 million downloads.

Now we are ready to roll. To run a development build, go to the Terminal menu and select Run build Task…. From the options, choose [YourProjectName]Editor Mac Development Build. This will build your project, and you will be able to see any changes you made with the Unreal Engine Editor UI. Run a quick rebuild, from within Unreal Engine Editor, by clicking the “Recompile on the fly” button in the status bar at the bottom right of the screen.

🎮 Editing Unreal Engine C++ Code in Neovim

The process above works fine, though, depending on your setup and project, you might appreciate the benefits of a lean editor like Neovide. So, let’s see how to configure Neovim to run with Unreal Engine.

On macOS, Unreal Engine uses the Clang compiler. Clang is highly configurable and fantastic for working with Neovim. You will need the LSP plugin with Clang set up in your Neovim installation to get code completion, linting, quick fixes and so on.

Unreal Engine does not officially support Neovim, but to generate project files required below, you can use Unreal Engine, as described above, for VS Code. For a detailed guide on setting up Neovim generally, with LSP and more, see this excellent tutorial from Jake Wiesler.

For LSP with Plug you will add something like this to your Neovim init.vim config file:

Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/nvim-cmp'
Plug 'hrsh7th/cmp-nvim-lsp'
Enter fullscreen mode Exit fullscreen mode

The last two plugins help provide autocompletion.

Then, add some Clang-specific config to your LSP config:

local on_attach = function(client, bufnr)
  -- TRUNCATED...
end

local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities = require('cmp_nvim_lsp').default_capabilities(capabilities)

local servers = { 'clangd' }
for _, lsp in ipairs(servers) do
    nvim_lsp[lsp].setup  {
        capabilities = capabilities,
        on_attach = on_attach,
    }
end
Enter fullscreen mode Exit fullscreen mode

Apart from this config, you shouldn’t need any more setup, just to have Clang 11 or newer installed on your system, which you should already have from installing Xcode. You can see LSP Clang configuration options in the project GitHub repo, though.

Creating a Project compile_commands.json

To get the most out of Neovim, you will need one more config file: compile_commands.json. This is a Clang requirement, which lets the compiler tooling provide completions and lints for your Unreal project. You can generate it by running a command, from the Terminal:

"/Users/Shared/Epic\ Games/UE_5.3/Engine/Build/BatchFiles/Mac/Build.sh" \\
-mode=GenerateClangDatabase \\
-project=/Path/to/your/project/YourProjectName/YourProjectName.uproject \\
-game -engine [YourProjectName]Editor Mac Development  
Enter fullscreen mode Exit fullscreen mode

Update the Unreal Engine path if you are using a different version or have it installed elsewhere.

If this has run successfully, you should see a message telling you where Unreal Engine output the JSON file to:

ClangDatabase written to /Users/Shared/Epic Games/UE_5.3/compile_commands.json
Enter fullscreen mode Exit fullscreen mode

Copy this output file to the root folder of your project, and now you should have code completion etc..

Unreal Engine with Neovim: Screen capture shows an Unreal Engine C++ actor file being edited in Neovim.  The user has pulled up the documentation for the Unreal Engine SetActorLocation A P I, shown in the top half of the editor window.

Building your project from the Terminal

To build your project, you will run command:

/Users/Shared/Epic\ Games/UE_5.3/Engine/Build/BatchFiles/Mac/Build.sh \\
"/Path/to/your/project/YourProjectName/YourProjectName.uproject" \\
-game -engine [YourProjectName]Editor Target Development Mac    
Enter fullscreen mode Exit fullscreen mode

Again, update the command to match your Unreal Engine version and exact path. See other available build commands by scanning through the [YourProjectName].code-workspace file in the root directory of your project.

🛁 Adding Linting Configuration

To add linting to your Unreal project, using Clang tooling, just add a .clang-tidy file to your project root directory. If you do not yet have one, as a starting point, choose:

🙌🏽 Unreal Engine with Neovim: Wrapping Up

In this Unreal Engine with Neovim post, we saw how you can get going with game development in Unreal Engine and Neovim. More specifically, we saw:

  • some pointers on setting up Unreal Engine for C++ coding with macOS;
  • how to generate a Clang compile_commands.json file for your Unreal Engine project; and
  • how to configure Neovim with Unreal Engine code quick fixes, lints and more.

I hope you found this useful. Do let me know if you found this content useful and would like to see more similar content. Also reach out if there is anything I could improve to provide a better experience for you.

🙏🏽 Unreal Engine with Neovim: Feedback

If you have found this post useful, see links below for further related content on this site. Let me know if there are any ways I can improve on it. I hope you will use the code or starter in your own projects. Be sure to share your work on X, giving me a mention, so I can see what you did. Finally, be sure to let me know ideas for other short videos you would like to see. Read on to find ways to get in touch, further below. If you have found this post useful, even though you can only afford even a tiny contribution, please consider supporting me through Buy me a Coffee.

Finally, feel free to share the post on your social media accounts for all your followers who will find it useful. As well as leaving a comment below, you can get in touch via @askRodney on X (previously Twitter) and also askRodney on Telegram. Also, see further ways to get in touch with Rodney Lab. I post regularly on Deno as well as Search Engine Optimization among other topics. Also, subscribe to the newsletter to keep up-to-date with our latest projects.

Top comments (0)