Unresolved External Symbol when Using Widget Component

Hi,
I have been struggling with this issue for a few minutes now, and am unable to find a solution.

I am using a widget component attached to what is pretty much the default C++ character class, have it configured in my header and cpp files, and I have the #include file for the widget component.

Here is the compile log error entry:

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

Here Is My Header

		UPROPERTY(VisibleAnywhere, BlueprintReadOnly, meta=(AllowPrivateAccess = "true"))
		class UWidgetComponent* UIWidget;

Here is my CPP

#include "Components/WidgetComponent.h"	

// User Interface
		UIWidget = CreateDefaultSubobject<UWidgetComponent>(TEXT("User Widget"));
		UIWidget->SetupAttachment(FPCamera);

Any help would be greatly appreciated!

Hey, so after some investigation this appears to have been an engine bug, because compiling the code in Visual Studio took care of it. As of right now I have been unable to reproduce the issue, although it is working perfectly fine now.

I also had this error but couldn’t compile (currently using Rider, not VS). Turns out that in the PublicDependencyModuleNames of your build.cs file, you need to add “UMG” which fixes the problem.

13 Likes

This right here is the answer. Odds are is that module wasn’t added the build cs file in OP’s post.