<style>.lazy{display:none}</style> Skip to main content

Unreal C++ with CLion 2018

By October 18, 2018December 10th, 2018Development, Tutorial

Recently I started playing around with a few alternative editors to Visual Studio Community 2017, specifically Visual Studio Code and CLion.

Coming from a Java background it was nice to see that the JetBrains folks have also brought their IDE wizardry to C++ in the form of CLion.

Please note that I am running this setup with the following app / os versions but with some minor tweaks this should be transferable to macOS and linux.

  • Unreal Engine 4.20.3
  • CLion 2018.2
  • Windows 10

In order to get unreal going with CLion you need to do a few things

  • Ensure that you either have Visual Studio Community 2017  installed or alternatively just the Visual Studio Build Tools as you need something to still compile the code.
    • CLion should automagically recognize what you have installed and assign the correct compiler configurations
  • Download the latest and greatest version of CLion
  • Once installed / setup open it up and navigate to the plugins panel ( Settings -> Plugins )
  • Install the Unreal Engine SDK Support Plugin


At this point we need to setup the Unreal side of the things

  • Open Unreal Editor ( source or binary doesn’t matter )
  • Go to Edit -> Editor Preferences

  • Then go to General -> Source Code -> Source Code Editor and select CLion

  • Once this is done you should now be able to generate a new CLion project  using File -> Generate CLion Project

  • This generation step will take a few seconds to complete
  • Once complete you should restart Unreal Editor before opening up CLion
    • NOTE: not sure why this occurs but generating the project and launching it immediately does not correctly configure it. I found that making adjustments to the CMakeLists.txt file and setting the build process to Release prior to launching CLion seems to clear up a lot of things. See below for details.
  • To open up CLion go to File -> Open CLion

At this point Unreal should be launching CLion and presenting you with your project structure that looks similar to this.

Almost there, we just have a few more things to complete before you are able to get back to building your game:

  • Ensure that you are picking your Project + Editor as your Build Target. This is so you can compile in CLion and get hot swapping in Unreal Editor.
  • Alternatively if you are building different targets make sure those are selected.

  • Ensure that you mark your Source folder as part of CLion project definitions so intellisense / autocomplete works correctly
  • This is not required but helps with navigating your project

That’s it !

And that is it as far as configuration goes. You should be able to build your project using CTRL + F9 and see your changes reflected in the Unreal Editor / your game.

The compile times are similar to Visual Studio but the richness of the CLion tool suite makes development a lot easier to traverse. Specifically have a look at the various shortcuts that come with CLion.

 

 

Additional Troubleshooting

There are a handful of issues I ran into while compiling this article. If you come across anything similar here are a few instructions that should hopefully help.

Dealing with invalid CMakeLists.txt file

The CMakeLists.txt file when generated by Unreal sometimes will contain non escaped backslashes, \ vs \\ , which will have to be adjusted manually.

Example of invalid backslashes

Corrected versions.

Command line error D8049

If you come across this error when trying to compile your CMakeLists.txt file it is most likely tied to building with Debug instead of Release.

To correct go to Settings -> Build, Execution, Deployment -> CMake and change the Build Type from Debug to Release.

 

Deleting CLion references and changing back to a different editor

In case you are not happy with CLion and want to revert things back to use Visual Studio I recommend cleaning up the files the CLion integration generated.

Specifically the following folders / files inside of your root project:


.idea/
cmake-build-debug/
cmake-build-release/
Intermediate/ProjectFiles/*.cmake
CMakeLists.txt

Once this is complete you simply follow the initial set of instructions but instead of picking CLion just select Visual Studio. This should then give you the option to re-generate the Visual Studio project within Unreal Editor ( File -> Refresh / Generate Visual Studio Project )

Source:

https://blog.jetbrains.com/clion/2016/10/clion-and-ue4/

https://answers.unrealengine.com/questions/811610/clion-with-ue-420-command-line-error-d8049.html

 

 

8 Comments

  • Cagdas says:

    I don’t know why but in my case Clion can’t detect the libs and classes even though I did escaped backslashes at CMakeList.txt

    https://imgur.com/rEEh7qS
    https://imgur.com/UzJPjyj

    I don’t know what’s wrong with my setup. Windows 10, Unreal Engine 2.21.1, Clion 2018.3

    Can you help me?

    • Wojtek says:

      Hi Cagdas,

      Your setup as far as I can tell seems to be ok but perhaps you can try a few things. I noticed that your path is somewhere in your c:\Users\cagdas\…. and the folders at the end look like they have spaces in them. You could try creating a new project in a folder that is shorter in length and does not include spaces as part of the name definition.

      So if you were to create your project in c:\projects\projectname and see if that helps. Sometimes the editors have a hard time with lengthly and space filled definitions.

      The other thing you should try is a bit of a weird set of steps but I have seen it unblock my own project.

      1) Re-generate the c++ project files from your ue4project ( right click and re-generate )
      2) Open up Unreal and open up CLion via Unreal
      3) Correct all the files ( clean up back slashes, etc )
      4) Shut down CLion and Unreal
      5) Open up Unreal again and launch CLion from it
      6) Reload the CMakeLists.txt file in CLion

      This force all the applications to clean up after themselves in case they are holding on to some sort of cache.

      Outside of that if you can share your project as a zip file I can take a quick look with my setup.

  • Roger Wibrew says:

    Hello,

    I have managed to get this all working on my windows machine. I do have an issue however with CLion taking ages to parse the project and build symbols. This seems to be a regular issue raised but I can find no solution anywhere on the forums. I would not be overly bothered by this (around 15 min on my i7 with 16mb ram) but it seems to happen each time I restart CLion. I have gone back to Visual Studio because of it. I did increase my Heap allocation but this does not seem to solve the issue. Is this an issue you have seen also and how did you solve it?

    Thanks,

    Roger

  • Charles says:

    As of Unreal 4.22, the CMakeLists.txt file is now currently generated (no back-slashes)!

  • RAMJI says:

    PLEASE UPDATE THIS CONTENT TO THE LATEST CLION 2019 AND VISUAL STUDIO 2019 AND UNREAL ENGINE 4.22. It will be a great help.. if u do so.

  • Mark says:

    Thanks for this. Question for you – how to you get CLion working as well as other IDEs/languages. ie for me in CLion (or ANY C++ IDE) I always have red squigglies on imports. Pressing the period or -> after an object never shows a list of available options. I get no suggestions for auto imports. ie If I use GetCapsuleComponent, there is no help saying, “Import “Components/CapsuleComponent.h?”

    Basically it seems like C++ IDEs are useless? I get the same results in VS and VSCode. Versus C#/.NET or Webstorm and javascript where it imports headers automatically as you need them.

    I find that i have to manually type everything with no help. Constantly looking up header names to find out what to import. Any thoughts?

  • gunreal says:

    I followed your instructions with the following software versions installed:
    – CLion 2019.1
    – UE 4.22.3
    – Visual Studio 2019 (16.1.6)

    I was able to generate the CMakeLists.txt but when I select “File | Open CLion” from the UE menu it fails with this messages: “Could not open CLion for project D:/dev/unreal/TL_Proj01/TL_Proj01.sln”.

    This does not make sense to me. It looks like UE still wants to open the VS project despite the fact that I changed the editor setting to use CLion (also as the new default). Also, the file TL_Proj01.sln does exist and it works fine with Visual Studio 2019.

    The generated CMakeLists.txt is using forward slashes for all paths so I think this should be fine.

    Could you please give a hint what might needs to be adjusted?

    Thanks!