# Can't use MotionControllerComponent from C++

**URL:** <https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059>\
**Category:** XR Development\
**Tags:** Motion-Controller, unreal-engine, CPP, question\
**Created:** [February 6, 2017, 8:54am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059 "2017-02-06T08:54:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Arshia001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arshia001](https://forums.unrealengine.com/u/Arshia001)\
**Post date:** [February 6, 2017, 8:54am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/1 "2017-02-06T08:54:06Z")

</div>

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

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

UCLASS()
class MYPROJECT_API AVR_Pawn : public APawn
{
	GENERATED_BODY()

protected:
	UMotionControllerComponent* M;
...

```

gives me this error:

```
'IMotionController' uses undefined class 'HEADMOUNTEDDISPLAY_API'

```

As per [this question](https://answers.unrealengine.com/questions/17462/oculus-rift-support-broken-since-beta-6.html), I modified my Build.cs script to include

```
PrivateIncludePathModuleNames.Add("HeadMountedDisplay");

```

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?

* * *

EDIT:

```
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.

---

<div class="post-metadata">

**Author:** ![project.gheist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@project.gheist](https://forums.unrealengine.com/u/project.gheist)\
**Post date:** [February 6, 2017, 10:16am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/2 "2017-02-06T10:16:28Z")

</div>

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,

---

<div class="post-metadata">

**Author:** ![Arshia001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arshia001](https://forums.unrealengine.com/u/Arshia001)\
**Post date:** [February 6, 2017, 10:42am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/3 "2017-02-06T10:42:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Arshia001](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Arshia001](https://forums.unrealengine.com/u/Arshia001)\
**Post date:** [February 6, 2017, 10:43am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/4 "2017-02-06T10:43:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![project.gheist](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@project.gheist](https://forums.unrealengine.com/u/project.gheist)\
**Post date:** [February 6, 2017, 11:50am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/5 "2017-02-06T11:50:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sango265](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sango265](https://forums.unrealengine.com/u/Sango265)\
**Post date:** [July 14, 2022, 1:19am UTC](https://forums.unrealengine.com/t/cant-use-motioncontrollercomponent-from-c/384059/6 "2022-07-14T01:19:21Z")

</div>

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:

Solution/Games//.Build.cs

in the file is this line:

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

there you can include the dependency that you need.

🙂
