Skip to content

boocs/unreal-clangd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 

Repository files navigation

Unreal 5.2+ Clangd extension for VSCode (Intellisense+)

Windows users: There's a problem using older versions of of Unreal (such as 5.4) with newer versions of C++ libraries. Info and fix are available here

Table of Contents



Updates

New info Mar 15, 2025

This page has been updated. New sections and updated info.

New info Feb 12, 2025

Windows: Should use LLVM (clang-cl/clangd) 18.1.3-18.1.8 for Unreal 5.5.# . Note: Linux is still recommended for 18.1.0

Updated Quick Start Guide: Updated below to latest/correct info

New update Nov 30, 2024

Extension v2.6.1: For Unreal 5.2 and newer releases

  • Changed Mac fix default setting

Also from older release:

  • Has Unreal Source file support (finally!) see here
  • UE 5.5 support (note: now uses clang/clangd v18.1.0)
  • Potential Mac fix
  • See Changelog for more info

Back to Top


Important Info

  1. This extension now uses UBT to Refresh your project to update Intellisense files(compile commands). So this runs when you run the 'Update Compile Commands' command. Since this refreshes your project, your project's *.code-workspace file will be refreshed removing your clangd settings and others! but...

  2. This extension will automatically backup and restore your clangd settings when you run the Update Compile Commands command.

  3. Make sure not to use any other way to Refresh your project.

Note: I've added a setting that allows you to add additional settings to be backed up. See change log for more info: https://github.com/boocs/unreal-clangd/blob/v2/CHANGELOG.md#250-2024-05-05

Back to Top


Info

This extension:

  • Provides fast Code Completion, Formatting, and other cool features!

  • Has a command to create a clangd project for you

  • Fixes some clangd/Unreal quirks

  • Has a uninstall command

    Note: Windows users can use clang/clangd for Intellisense and still build with Microsoft's compiler

Back to Top


Requirements

General :

  • Unreal v5.2+
  • LLVM (clang/clangd) Different Unreal versions requirement different LLVM versions (see below)
  • Unreal project created for VSCode
  • VSCode clangd extension (Do not let the VSCode clangd extension auto install LLVM)
  • Microsoft C++ extension for its Building/Debugging Capability

Compiler and libraries :

note: The links below will tell you the requirements for Unreal 5.5.#

  1. Unreal 5.5 Release Notes (Platform SDK Upgrades)

    • Note: The link above can take too long to load so might not take you to the right section (Platform SDK Upgrades)
    • Try loading link twice
    • Windows: Best resource (has everything you need)
      • Shows different .NET versions needed
      • Shows LLVM (clang/clangd) version needed
      • Shows Windows SDK version needed
      • Shows The C++ library needed
      • Note: I would recommend using the versions mentioned in the section IDE Version the Build farm compiles against
      • See: Installing correct library versions (Windows)
    • Also shows useful Linux/Mac info
  2. Unreal Docs: Hardware and Software Specifications

    • Useful info for Linux and Mac (Not that useful for Windows)
    • Use Operating System dropdown to change to Linux/Mac
    • You can change Unreal Engine version on left hand side
  3. Unreal Docs: Linux Development Requirements

    • Shows useful Linux info
    • You can change Unreal Engine version on left hand side
  4. Unreal Docs: MacOS Development Requirements

    • Shows usefull Mac info
    • You can change Unreal Engine version on left hand side

Back to Top


Other Recommended Extensions

  • Microsoft's C++ Needed for Building/Debugging

  • File Switcher For Alt+O clangd keyboard shortcut (Head/Source switcher) Using Clangd's Alt+O implementation is buggy, for Unreal Source files, so this extension is a good alternative

  • C++ Create Definition (my extension) Updated Sept 2023

  • [Unreal Reflection Function Parameters] (Deprecated) New project coming soonish

Back to Top


Quick Start Guide (UE 5.2+)

This is generally correct, when using non-full source, but your situation could be different.

  1. Read the Requirements section
    • Different Unreal Engine versions require different LLVM versions(Unreal 5.5 requires LLVM 18.1.0(Linux) and LLVM 18.1.8(Windows))

  1. Install the vsix file from this github

    (The vsix file can be downloaded from the Releases section on the right side column of this page. You might have to scroll up to see it.)

  • Click the extensions icon
  • Click the ellipsis (3 dots)
  • Choose Install from VSIX...

  1. Ignore any VSCode warning messages (should go away after creating a project)

  1. Linux: In the next step(project creation), File Dialogues will spawn behind VSCode(known bug)

  1. Run extension command "Create Unreal clangd project" on your Unreal project
    • Example:

      image


  1. Use the Editor suffix and Development config when Building/Running
    • Build

      image


    • Run/Debug

      image


  1. Use Editor suffix and DebugGame when you have to Debug something.
    • Debugging

      image


  1. Run extension command 'Update Compile Commands' to fix fake red squiggles that may rarely happen.

    image

Back to Top


Documentation

Unreal 5.2+

Note: Make sure to read requirements! Different Unreal version usually require different clang/clangd and XCode versions

Windows Users: The requirements sections has easy instructions on how to install different Build Tools 2022 versions. These are required because other versions may cause fake red error squiggles.

Back to Top


Upgrading Older Projects

This version had some changes!


Mac support

This hasn't been proven to work yet(let me know!).

There a new setting to try if you haven't been successful in getting clangd to work.

unreal-clangd.creation.MacFileLanguage

You can change the clangd Mac file language to C++ or Objective C++ (thanks to user szabot0412)

  • The Objective C++ setting, -xobjective-c++, is a misnomer. It just means it will treat Objective C++ files as Objective C++ and C++ files as C++
  • This setting is set in your .clangd files during project creation (.clangd file in project directory and Unreal directory)
  • in the Add: section, it's the line that shows - -xc++ or - -xobjective-c++ so if you want to test quickly with reinstalling. I believe - -xobjective-c++ is the correct one to use but I could be wrong!

Back to Top


Troubleshooting

GENERATED_BODY Macro causing red error squiggles

Adding code or a space, in a header file, anywhere above the GENERATED_BODY macro will cause red squiggles. This is because the GENERATED_BODY macro uses the __LINE__ preprocessor macro.

Image

  1. You'll need to Build your project to get rid of the red squiggles.
  2. Now you'll need to get clangd to reevaluate the file. See the Refresh File's Instellisense section below

Refresh File's Intellisense

  • You can type a space in the file, wait half a second, and delete the space (this makes clangd reevaluate the file)
  • You can also run the command clangd: Restart language server (on restart clangd will reevaluate the file)
  • Or you can close and reopen the file

Your project's VSCode *.code-workspace file

The extension pulls the Unreal Uri from your project's *.code-workspace file. If you don't create a Unreal (VSCode) project then this file isn't created. You also must double click this file to open your project as a 'Workspace'. You can force Unreal to always create a VSCode project with a BuildConfiguration.xml file.

  1. *.code-workspace file

    Image

  2. When you double click on the file you'll see 'Workspace' in the VSCode title area: Image

  3. When you open VSCode without a project, you'll get this screen which also tells you if you're opening as a 'Workspace'

    Image


Code completion sometimes doesn't work

I've run into this bug. Pressing control+space (Windows) will manually activate Code Completion. Look up your keyboard shortcut for your system.


Plugins

If you add a plugin to *.build.cs you'll need to run the extension command to Update Compile Commands.

See this section for more info


Create Full Source Unreal Engine projects

  1. Double click on the UE5.code-workspace file in your Unreal directory
  2. Build the Editor inside VSCode
  3. Since you want to Launch it after it's done you can just use Run And Debug instead of Run Build Task. Unless you're heavily debugging you'll want to use the Development config. Image
  4. Once you set the above you can run it by hitting the F5 key or ctrl+F5 to run it without debugging.
  5. After it builds the Editor should run and you can now create a Full Source project.
  6. This is what pops up after I'm done compiling and it runs: (This is full source 5.4.1) Image

Back to Top


(bug) Older Unreal versions with newer C++ libraries (Windows only)

Thanks to user nmdMnk for the report!

Unreal 5.4.# example:

  1. Unreal 5.4 on Windows requires clang 16.0.6
  2. Unreal 5.4's defaults are MSVC 14.38.33130 and Windows 10 SDK 10.0.18362.0 (according to 5.4 release notes)
  3. Trouble is Unreal 5.4 can and will use newer versions of MSVC and Windows 10 SDKs
  4. Newer MSVC versions require clang 18+
  5. So now you get errors if you have the updated C++ libraries.

There are 2 fixes:

1. Unreal 5.4.# simple fix

This fix might work better if you're using Visual Studio Build Tools 2022 instead of relying on Visual Studio 2022's libraries.

Note: This 'simple' fix isn't for everyone. Uninstalling and preventing newer C++ library updates is easy but might cause problems elsewhere. Also you might forget that you did this and, in the future, wonder why newer versions of Unreal aren't working.

The 2nd fix, below this fix, takes a little more work but works within clangd to fix it.

1st Fix:

  1. Simple fix would be to uninstall the newer C++ libraries and Windows 10 SDKs

  2. The Visual Studio Installer allows you to do this

  3. Check out the 2nd fix below for pictures of modifying the Visual Studio Installer

  4. You will want to uninstall any MSVC versions above 14.38

  5. Make sure to also remove the checkmark to always install the latest MSVC version

    Image

  6. Also make sure to uninstall any Windows 10 SDKs above 10.0.18362.0

2. Unreal 5.4.# Fix:

If you don't want to do the first fix this fix works within clangd to fix the problem. You won't have to worry about uninstalling anything.

  1. Add this to both .clangd files (your project and Unreal directory) Add it to the 'Add' section.

    Add:
        - /X
        - -fms-compatibility-version=19.38.33144
        - /imsvcC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include
        - /imsvcC:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\ucrt
        - /imsvcC:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\shared
        - /imsvcC:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\um
        - /imsvcC:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\winrt
        - /imsvcC:\Program Files (x86)\Windows Kits\10\Include\10.0.18362.0\cppwinrt
    
  2. All/some paths might be different so you'll have to adjust them (note the single backslash)

    1. Your path also might be different because you're using Visual Studio 2022 and not Visual Studio Build Tools like I am
    2. Visual Studio 2022 follows the same pattern as Visual Studio Build Tools 2022
    3. Here is a users example of the path he used for Visual Studio 2022
      - /imsvcC:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.38.33130\include
      
  3. All version numbers are correct and you should probably use them

  4. When you check the 5.4 release notes it says for Windows that MSVC 14.38.33130 and Windows 10 SDK 10.0.18362.0 are the default

  5. You can download different MSVC versions from the Visual Studio Installer

    Image

  6. You can download different Windows 10 SDKs from the Visual Studio Installer

    Image

  7. /X was the key. It prevents clangd from pulling the version from a environmental variable

  8. You can make sure -fms-compatibility-version=19.38.33144 is correct by doing .\cl in powershell. Here's what it looks like:

    Image

  9. Note: 5.5.# currently doesn't have this problem. If it does in the future, it actually has another include to use.

     - /imsvcC:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\atlmfc\include\
    

    So in the future this fix might need to adjust to the newer includes of future Unreal Engine releases.

Back to Top


Create a BuildConfiguration.xml

To make Unreal Build Tool create a VSCode project by default you can use a BuildConfiguration.xml file. Here is the info about which directories you can create it in and what options are available.

https://dev.epicgames.com/documentation/en-us/unreal-engine/build-configuration-for-unreal-engine

Note: On Windows I created the directory structure and xml file in my Documents folder (ME is my user name so it will be different for you):

E:\Users\ME\Documents\Unreal Engine\UnrealBuildTool\BuildConfiguration.xml

Here's a basic BuildConfiguration.xml (It's easy to create all this using VSCode)

<?xml version="1.0" encoding="utf-8" ?>
<Configuration xmlns="https://www.unrealengine.com/BuildConfiguration">
    <ProjectFileGenerator>
      <Format>VisualStudioCode</Format>
    </ProjectFileGenerator>
</Configuration>

Back to Top


Installing correct LLVM (clangd/clang) version

note: These examples are for Unreal 5.5.#. Make sure you get the correct library and compiler versions for your specific Unreal version

Windows

  1. Get the correct LLVM (clangd/clang) version from the Release Notes of your Unreal version.
  2. If you check out the Release Notes link for 5.5.# you see that Windows uses LLVM 18.1.8
  3. You can download it here: https://github.com/llvm/llvm-project/releases/tag/llvmorg-18.1.8
  4. The file you want is: LLVM-18.1.8-win64.exe

Linux

  1. Any of the links in All supported Unreal version requirements links will tell you which version of LLVM (clangd/clang) to install
  2. It's hard on Linux to install specific versions unless you want to compile it yourself
  3. You can try the latest of the version it recommends but might run into issues
    • If you do run into issues try compiling/using the correct version
  4. Here's how I've had success installing version 18 for Unreal 5.5.#
    • Note: This installs 18.1.8 but 18.1.0 is the recommendation for Linux and Unreal 5.5.#
    wget https://apt.llvm.org/llvm.sh
    chmod +x llvm.sh
    sudo ./llvm.sh 18
    
  5. dotnet-runtime-6.0 and dotnet-sdk-6.0 might also be required but doesn't say in any of the requirement links.
    • This was true in Unreal ~5.2.
    • Maybe not required or newer versions required now.

Mac

  1. Unreal docs doesn't give specifics about clang/clangd like it does Windows/Linux
  2. It gives Xcode versions, which you should install for its libraries.
    • I recommend the Xcode version listed in the Unreal Release Notes for your Unreal version - Section: Platform SDK Upgrades Subsection: IDE version the Build farm compiles against
    • See All supported Unreal version requirements links for link to Release Notes
  3. For what LLVM (clang/clangd) version to install I would try following the Linux instructions
    • If that doesn't work go to your project's .vscode folder
    • Open up one of the compile commands JSON files that are in there.
    • Check which compiler it's using.
    • Open the compiler's parent folder in your terminal and poll it for version info
    • Install the LLVM version which matches the compiler you just polled

Back to Requirements

Back to Top


Installing correct library versions (Windows)

Windows

Note: In the 3.0.0 extension release, you can choose the C++ library and Windows SDK the project uses. This can minimize problems.

  1. Run the Visual Studio Installer to install other versions of:

    • C++ Libraries
    • Windows SDK
    • .NET libraries
  2. I use the stand-alone Visual Studio Build Tools 2022 but this also should work if you have the Visual Studio 2022 IDE installed.

  3. This example is for Unreal 5.5.# but it can apply to older Unreal versions. Older versions will probably require different clangd/library versions so make sure to see here for older version requirement links: Older Version Requirement Links

  4. From the Visual Studio installer click on Modify next to Build Tools 2022 or VS 2022 IDE

    image

  5. Switch the tab to Individual components (To make it easier use Search Components box)

    image

  6. Windows users will most likely find all requirements in the Unreal Release Notes (Platform SDK Upgrades section): Unreal 5.5 Release Notes

    • Note: The 'release notes' link is slow to load so wont take you to the correct 'Platform SDK Upgrades' section unless you load twice.
    • Use C++/Windows SDK versions found in the subsection IDE Versions the Build farm compiles against. Found under the Platform SDK Upgrades section.

Below are the versions found in the Unreal 5.5 Release Notes and what they look like in the Visual Studio Installer (Individual components).

  1. Here's the Platform SDK Upgrades section in the Unreal 5.5 Release Notes

    • For older Unreal version Release Notes see here

    Image

  2. Visual Studio 2022 17.8 14.38.33130 (In subsection: 'IDE Version the Build farm compiles against' in 5.5 release notes)

    • Some other entries look similiar.
    • Note the x64/x86 build tools

    Image

  3. Windows 10 SDK (10.0.22621.0) (In subsection: 'IDE Version the Build farm compiles against' in 5.5 release notes)

    • Windows 11: Use same version number unless specified

    Image

  4. .NET 8.0 (Found in Unreal Release Notes. Platform SDK Upgrades section):

    image

  5. .NET 4.6.2 Targeting Pack(Found in Unreal Release Notes. Platform SDK Upgrades section):

    Image

  6. Make sure to click the Visual Studio Installer's Modify button to install your new libraries.

    Image

Back to Requirements

Back to Top


All supported Unreal version requirement links

Unreal 5.5.#

Release Notes: 5.5.# (Platform SDK Upgrades)

Unreal Docs Requirements: Requirements

Unreal Docs Linux Requirements Linux

Unreal Docs MacOS requirements MacOS

Unreal 5.4.#

Release Note: 5.4.# (Platform SDK Upgrades)

Unreal Docs Requirements: Requirements

Unreal Docs Linux Requirements: Linux

Unreal Docs MacOS Requirements: MacOS

Unreal 5.3.#

Release Note: 5.3.# (Platform SDK Upgrades)

Unreal Docs Requirements: Requirements

Unreal Docs Linux Requirements: Linux

Unreal Docs MacOS Requirements: MacOS

Unreal 5.2.#

Release Note: 5.2.# (Platform SDK Upgrades)

Unreal Docs Requirements: Requirements

Unreal Docs Linux Requirements: Linux

Unreal Docs MacOS Requirements: MacOS

Back to Requirements

Back to Top