Clion can't deal with 'UCLASS()'

platform: Ubuntu 16.04

Unreal Engine: 4.21.1 (build with release branch)

Clion: 2018.2

When I generated a C++ project and waited for Clion to finish the indexing job, I found that the IDE cannot deal with “UCLASS()” well, And the reason is “unknown type name ‘Engine_Source_Runtime_Engine_Classes_GameFramework_GameModeBase_h_12_PROLOG’”(As shown in the picture), and this lead to all auto complete features not working in this class.

Weird thing is that it can be build successfully.
Another weird thing is that as you can see, the IDE cannot find “ClionTestGameModeBase.generated.h”, I noticed that the path(/UE4Projects/ClionTest/Intermediate/Build/Linux/B4D820EA/UE4Editor/Inc) which “ClionTestGameModeBase.generated.h” exist is not included by cmake, and even I used include_directories() to force include the path, nothing happens, the folder is still red. And, still, it can be build successfully.

I like Clion for it’s powerful indexing and auto complete feature, but this issue make all this not working, anybody knows why this happens?

I’v found the root case, this issue happens because CLion could not found *.generated.h and lead to deal with ‘UCLASS’ incorrectly. There’s two reason why CLion could not find *.generated.h:

  1. in .idea folder, there’s a file named misc.xml which tell the IDE to treat Intermediate folder as “exclude”
  2. there’s no rules to add “UE4Projects/ProjectName/Intermediate/Build/Linux/B4D820EA/UE4Editor/Inc/ProjectName” to the include dir.

I have to modify the misc.xml and add “UE4Projects/ProjectName/Intermediate/Build/Linux/B4D820EA/UE4Editor/Inc/ProjectName” to include dir in cmake, but this has to be done every time I refresh the clion project in UE4 editor, which is annoying.

I dive into the source code and found “Engine/Source/Programs/UnrealBuildTool/ProjectFiles/CMake/CMakefileGenerator.cs” is the file to generate the misc.xml, but I still can’t find where is the code to generate the cmake-includes.cmake.

This Issue is exactly the problem I met, but it exists since at least 4.19. I don’t understand how QA would miss this, since this is such an obvious bug.

I’m the one who reported the issue you mentioned. According to the email response I got from QA(?) an IDE is not supposed to actually parse and index the “*.generated.h” headers. Instead the UCLASS macro should evaluate to “nothing” when evaluated by the IDE. This is the case for VisualStudio which defines __INTELLISENSE__. CLion defines __JETBRAINS_IDE__ but apparently nobody bothered with updating the code, yet.

Edit: You can sort of manully fix this by extending the preprocessor checks in ObjectMacro.h to this #if UE_BUILD_DOCS || defined(__INTELLISENSE__) || defined(__JETBRAINS_IDE__)

there’s a pull request which will fix this problem, but it has been hold there for a long time and not merged yet. I use some part of commits in this pr, and the problem is solved. I prefer to let the IDE know about the macro.

I have met this problem too. That’s my solution.

  1. Open CMakefileGenerator.cs

  2. Goto function WriteCMakeLists(). Just search the key words “foreach (FileReference CurModuleFile in AllModuleFiles)”

  3. Add these code before the end of this code block

    if (CurModuleFile.IsUnderDirectory(DirectoryReference.Combine(OnlyGameProject.Directory, “Source”)))
    {
    var FileName = CurModuleFile.GetFileName();
    var ModuleName = FileName.Substring(0, FileName.LastIndexOf(“.Build.cs”));
    var IncPath = DirectoryReference.Combine(OnlyGameProject.Directory, “Intermediate”, “Build”, “Win64”, “UE4Editor”, “Inc”, ModuleName);
    IncludeDirectories.Add(IncPath.FullName);
    }

These code will write directories which include *.generate.h into cmake-includes.cmake file. And my platform is Win64. You can modify the path codes on Linux.

if (CurModuleFile.IsUnderDirectory(DirectoryReference.Combine(OnlyGameProject.Directory, “Source”)))
{
var FileName = CurModuleFile.GetFileName();
var ModuleName = FileName.Substring(0, FileName.LastIndexOf(“.Build.cs”));
var IncPath = DirectoryReference.Combine(OnlyGameProject.Directory, “Intermediate”, “Build”, “Win64”, “UE4Editor”, “Inc”, ModuleName);
IncludeDirectories.Add(IncPath.FullName);
}