Linker errors with UMotionControllerComponent and UPROPERTY or UFUNCTION

Help

In all scenarios (including empty projects) the moment i expose UMotionControllerComponent with a UPROPERTY or UFUNCTION i get linker errors. It does not happen if i do it with any other classes (like UStaticMeshComponent), and it also works fine if i don't use the UPROPERTY or UFUNCTION.

The top has

#include "MotionControllerComponent.h"

And the bottom has (under public)

UPROPERTY(EditDefaultsOnly, Category = "Components")
		UMotionControllerComponent* MotionController;

And the error i get is

  MyActor.gen.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) class UClass * __cdecl Z_Construct_UClass_UMotionControllerComponent_NoRegister(void)" (__imp_?Z_Construct_UClass_UMotionControllerComponent_NoRegister@@YAPEAVUClass@@XZ) referenced in function "void __cdecl `dynamic initializer for 'public: static struct UE4CodeGen_Private::FObjectPropertyParams const Z_Construct_UClass_AMyActor_Statics::NewProp_MotionController''(void)" (??__E?NewProp_MotionController@Z_Construct_UClass_AMyActor_Statics@@2UFObjectPropertyParams@UE4CodeGen_Private@@B@@YAXXZ)

Anyone who has any ideas? Tried it in many clean projects now. Using unreal engine 4.24.3 and Visual Studio 2019. Also tried 4.24.2 and VS Code. I have steamvr running with a valve index if that changes anything

Posted Mar 2, 2020, 5:00 PM UTC

13
Woo42•

Your (ProjectName).Build.cs file is setup for basic gameplay functionality. If you add to this functionality you need to declare it in this file.

In this file find:

PrivateDependencyModuleNames.AddRange( ...

and add "HeadMountedDisplay"

2
ViterOP•

HeadMountedDisplay

It works! Ty so much, shouldn't this be default in the VR template? Also how do i figure stuff like this out in the future?

1
Woo42•

I suspected it was *.build.cs from my limited experience and I also had to add "NavigationSystem" to it from a paid Udemy course I'm currently doing.

I typed UMotionControllerComponent build.cs in google and it had the answer in the first link.


Also how do i figure stuff like this out in the future?

I wondered about how someone new would figure this out. I typed ue4 c++ virtual reality setup in google and found answers in the first few links.

They actually put "HeadMountedDisplay" in:

PrivateDependencyModuleNames.AddRange(...

instead of the Public one I mention.

https://www.tomlooman.com/getting-started-with-vr/

https://www.brightdevelopers.com/basics-c-unreal-engine-4-virtual-reality/

I don't know anything about why or when you should use Private over Public but I'd change it. I'm going to update my answer to reflect this new info.

2