C++ game development is strongly linked with Unreal Engine 4, one of the most popular and widely spread C++ game engines. It is no surprise that we are getting lots of requests about UE4 setup within CLion. In this blog post we’ll share our own experience along with a couple of tips and useful links.
The story started some time ago when one of our team members decided to try UE4. At that time CLion relied heavily on CMake project model (now it’s also Gradle and compilation database options), so it was crucial to get a CMake-based UE4 project. The official Linux-only CMake generator for UE4 projects had existed for some time, but it wasn’t perfect and more importantly, limited to Linux. Philipp Smorygo from the AppCode/CLion team investigated the source of this problem and contributed to Unreal Engine repository with his CMake + UE4 changes. You can read about his experience in his own blog.
Good news! With Unreal Engine v4.20 the things became much easier – Unreal Editor can now generate CMake project and open it in CLion in a couple of clicks!
Short instructions on how to get started with UE4 in CLion:
- Get the engine
- Register at Epic Games and download the Epic Games Launcher.
- Run it and let it download all the necessary Unreal Engine 4 binaries for you.
- Create or open your project with UE4 Editor to generate an *.uproject file.
- Get Mono
- Download and install Mono to be able to launch on Linux and macOS.
- Go to Unreal Editor settings, General | Source Code. Select CLion as an editor in the dropdown list. You can also make it default to survive the editor restart:
- Now you need to generate CMake for your Unreal Engine project. For this, go to File | Refresh CLion Project (don’t forget to do this every time you change the project, for example add a new class):
Now you can call File | Open CLion, use CLion for your UE4 project and enjoy all of its features! Bu the way, don’t forget to build your Unreal Engine project to get all the generated headers ready, otherwise the IDE won’t be able to resolve some symbols in your project.
Plugin also generates custom targets for building and cleaning your game. Fake target is added for CLion needs to make all the intellisense possible.
Unreal Engine 4 SDK Support plugin
If you write games with UE4 in CLion, you may also find useful an Unreal Engine 4 SDK Support plugin from Philipp, our team member. To install it, go to Preferences/Settings | Plugins and Browse repository to search for it:
The plugin adds extra completion options for reflection specifiers, which CLion is unable to provide by default:
Performance and known issues
Our experience shows that initial indexing time is acceptable, as the CMake project model generated this way allows CLion not to index and build symbols for the entire engine source, but only for necessary engine headers and source files.
However, we still recommend that you increase the amount of memory used by CLion, or at least check the real usage by switching on the memory indicator (Preferences/Settings | Appearance & Behavior | Appearance | Show memory indicator).
While on Linux and macOS this works fine, on Windows there are a few known issues:
- Unreal Engine generator produce CMakeLists.txt with the incorrect escaping sequence: use
\Uin the top-level CMake file.
- Often you might get CMake loading error (command line is too long) – it might be related to the MSVC bug (CPP-9026). Workaround: switch Build Type from Debug to Release (Settings -> Build, Execution, Deployment -> CMake).
One more general problem you might meet it failing CMake project loading (CPP-14457) with CLion 2018.3 EAP. If it happens to you, the workaround is simply to start CLion manually and open the project via pointing the IDE to the top-level CMakeLists.txt file (and not to the whole project directory). The issues is fixed in 2018.3 EAP, in stable version the fix will be delivered with 2018.3 release.
We’ll appreciate your feedback on the whole workflow! Let us know in the comments section below.