CLion is a great IDE. Lately, I’ve been using it to develop some games with Unreal Engine 4. I’ve created a step by step guide on how to do this. You can get and install CLion from https://www.jetbrains.com/clion/.
If using MS Windows
CLion doesn’t come with a compiler. If you are going to be doing any other C or C++ work with it you need one. At the time of writing, you can use the MSVC compiler changing some registry settings, but I recommend installing a better toolchain.
The easiest way I’ve found to setup the compiler is to download and install MSYS2 from http://www.msys2.org/. Once that is done just open “MSYS2 MinGW 64-bit” from the Start Menu and run:
pacman -S mingw-w64-x86_64-toolchain
Open CLion and go to Configure > Settings… > Build, Execution, Deployment > Toolchains and add a new Toolchain. Use this settings:
- Name: MinGW
- Environment: MinGW
- Path: C:\msys64\mingw64
Wait a few seconds for it to detect the compiler and just click OK.
If using Linux / MacOS
You are ready to continue.
UE4 Plugin for CLion (for UE4 >= 4.16)
Next you need to install the CLionSourceCodeAccess plugin. If using a git repo just go to your project folder and run:
git submodule add https://github.com/dotBunny/CLionSourceCodeAccess.git Plugins/CLionSourceCodeAccess
Lear more about git submodules here. If you are not using git, or don’t want to use submodules, download the plugin from https://github.com/dotBunny/CLionSourceCodeAccess/archive/master.zip and extract it to the Plugins folder (create that folder if it doesn’t exist). In any case you should end up with Plugins/CLionSourceCodeAccess/CLionSourceCodeAccess.uplugin and other related files.
After that just open the your UE4 project and let it compile the plugin. You need to set a couple more settings. Go to Edit > Project Settings… > Plugins > CLion and enter the following:
- C Compiler: C:/msys64/mingw64/bin/clang.exe
- C++ Compiler: C:/msys64/mingw64/bin/clang++.exe
- CLion executable: Select your clion.exe
- Mono path: You need this for Linux/MacOS
There’s more information about this plugin on https://github.com/dotBunny/CLionSourceCodeAccess. You can also get it from the UE4 marketplace at https://www.unrealengine.com/marketplace/clion-integration, but I haven’t tested that one.
Generating the CMake project file
The next step is generating the CMakeLists.txt file that CLion can open. For that just click on File > Generate CMakeLists. You need to do this every time you add or remove classes from your project.
You can now click on File > Open CLion and the project will open. Finally to open CLion automatically when you double click on any class in the UE4 editor, navigate to Edit > Editor Preferences… > General > Source Code and change the Source Code Editor there.
UE4 Plugin for CLion (for UE4 4.15)
For UE4 4.15 follow the previous procedure but replace the following items:
- Git repo: https://github.com/cesarizu/CLionSourceCodeAccess.git
- Download link: https://github.com/cesarizu/CLionSourceCodeAccess/archive/master.zip
Before opening CLion you need to change one file: Intermediates/ProjectFiles/Definitions.cmake. From that file, delete the line that reads:
You need to do this every time you run File > Generate CMakeLists.
Installing the Unreal Engine 4 SDK Support for CLion
There’s a plugin to get some extra functionality on CLion when working on UE4 projects. This will get rid of errors on UPROPERTY, UCLASS, USTRUCT and similar macros. On CLion go to File > Settings… > Plugins then click on Browse Repositories… and install Unreal Engine 4 SDK Support.
And voila! you can now benefit from the multiple features that CLion offers over other IDEs.
If there’s anything on this guide that doesn’t work or is incorrect, please let me know.