Custom component based on WidgetComponent won't compile

I created a custom c++ component based on WidgetComponent. The generated code won’t compile:

#pragma once

#include "Components/WidgetComponent.h"
#include "NpcStatusWidgetComponent.generated.h"

class STARGRIND_API UNpcStatusWidgetComponent : public UWidgetComponent

According to the compiler it can’t include “Components/WidgetComponent.h”. If I change the path to the actual location of WidgetComponent.h, the compilation fails because the generated file for WidgetComponent can’t be found.

Am I missing something major? Am I not supposed to derive from WidgetComponent? Or do I have to alter some configurations/makefiles so that the include paths for the widget component are set correctly?


Please note, that to use Widget Component class, you need to include UMG module. To do this, you should add “UMG” to the list of included modules in Buid.cs file of your project (you can find the file in this folder: YourProject/Source/YourProject/YourProject.Build.cs).
Please modify the line PublicDependencyModuleNames.AddRange, so it has the appropriate module:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore","RHI", "RenderCore", "ShaderCore", "UMG"});

After this, rebuild your project.

Hope this helped!


1 Like

That was the issue, thank you for your help!