Exceptions while compiling UserWidget.h in CPP

I am trying to write my own widget using C++, but when I create UserWidget.h C++ class and try to compile my project, it shows a lot of errors ( connected as I suppose with not implemented functions from UUserWidget ). I use Rider as my IDE. What could be a problem?

H:

#pragma once

#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "InteractionCrosshair.generated.h"


UCLASS()
class INTERACTION_API UInteractionCrosshair : public UUserWidget
{
	GENERATED_BODY()
	
};

Also logs:
log.txt (47.1 KB)

Remove

#include "Blueprint/UserWidget.h"

and add

#include "Runtime/UMG/Public/UMG.h"
#include "Runtime/UMG/Public/UMGStyle.h"
#include "Runtime/UMG/Public/Slate/SObjectWidget.h"
#include "Runtime/UMG/Public/IUMGModule.h"
#include "Runtime/UMG/Public/Blueprint/UserWidget.h"

Hopefully that solves it for you.

Unfortunately, it doesn’t help (

Can you show the errors?

It’s a linker error. You need to add “UMG” as a module dependency in your MyProject.Build.cs file.

You also don’t need all the includes posted above. All you need is “Blueprint/UserWidget.h”

3 Likes

Thanks. It works)

Thanks for help. Your method also works after TheJamsh’s solution.

I too learnt something new, seems I’ve added more headers than I need.
Less is more :slight_smile:

Only need those if you want to reference controls to bind. UButton and so forth.