Can't use MotionControllerComponent from C++

I’m having problems with using motion controllers from C++. Compiling this code:

#include "Runtime/HeadMountedDisplay/Public/MotionControllerComponent.h"
#include "VR_Pawn.generated.h"

class MYPROJECT_API AVR_Pawn : public APawn

	UMotionControllerComponent* M;

gives me this error:

'IMotionController' uses undefined class 'HEADMOUNTEDDISPLAY_API'

As per this question, I modified my Build.cs script to include


and now it works. However, the answer mentions “You should not need to do this, so there appears to be a regression.” and it also seems like a problem to me as well. Is this a (very old, yet still unfixed) problem or am I doing something entirely wrong?


M = CreateDefaultSubobject<UMotionControllerComponent>(FName(TEXT("Left Controller")));

results in:

unresolved external symbol "private: static class UClass * __cdecl UMotionControllerComponent::GetPrivateStaticClass(wchar_t const *)" (?GetPrivateStaticClass@UMotionControllerComponent@@CAPEAVUClass@@PEB_W@Z) referenced in function "public: class UMotionControllerComponent * __cdecl UObject::CreateDefaultSubobject<class UMotionControllerComponent>(class FName,bool)" (??$CreateDefaultSubobject@VUMotionControllerComponent@@@UObject@@QEAAPEAVUMotionControllerComponent@@VFName@@_N@Z)

so… not fixed after all.

1 Like

Hi Arshia001,

The reason you are getting those errors is because you are including the module incorrectly.

In your build.cs file you need to add the module to PublicDependencyModuleNames or the private one if you are only using classes from that module in the private folder.

After doing that you can simply include the header as #include "MotionControllerComponent.h". I would recommend using forward declaration for the class in the header file and including the file in the cpp.

Hope that helps. Cheers,

Yeah, that fixes it. Total noob question. Sorry.

I can’t seem to find any documents which explain the build system in-depth…

I don’t think there is any that does that in depth.

The build.cs file is in your project.
When you open VisualStudio, in the Solution explorer, there are two folders, Engine and Games.
In the Games folder is Source, an inside is your Project Folder:


in the file is this line:

PublicDependencyModuleNames.AddRange(new string[] { “Core”, “CoreUObject”, “Engine”, “InputCore”});

there you can include the dependency that you need.