Creating widgets in c++ with UPROPERTY()

Hello,

I’m trying to make myself a UUserWidget in c++ and expose it to blueprints with the UPROPERTY()-macro. However I’m just getting very confusing errors.

Yes, I’ve added “Slate” and “SlateCore” to my PublicDependenciesModule in MyProjectName.Build.cs, as you can see here:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Slate", 
"SlateCore" });

I’m creating my widgets in my player controller, and have forward declared the UUserWidget class like this:

class UUserWidget;

UCLASS()
class SHOOTERGAME_API APrimalPlayerController : public APlayerController
{
    GENERATED_BODY()

public:

    APrimalPlayerController();

protected:
    // Called when the game starts or when spawned
    virtual void BeginPlay() override;

    // INVENTORY

    UPROPERTY(EditDefaultsOnly BlueprintReadWrite, Category = "Inventory|Widgets")
    TSubclassOf<UUserWidget> InventoryWindow;

public:

    virtual void SetupInputComponent() override;

};

If you want to see my errors, here they are:

So, I don’t know what I’m doing wrong. What I simply want to do is assign the UPROPERTY()-macro to my UUserWidget variable, but doing so only returns me some error-messages. Even leaving the macro blank without any specifiers. However, when I remove the UPROPERTY()-macro from my variable the code compiles fine.

Any ideas? Thanks in advance! :slight_smile:

Stefan!

Please show output tab errors as error tab is very misinforming with UBT, documentation even suggest to disable “Always show Error List if build finishes with error” option because of it.

I don’t know if this is the cause as the error tab don’t show linker error, but adding Slate and SlateCore is not enough. Slate is UI system made originally for editor, but can be used in game, but because it extensivly functions outside of UObject system it cannot be used with blueprints, thats why UMG was made that wraps Slate function in to UObject classes, in fact name UMG the Unreal Motion Graphics takes more from it’s animating features which are harder to do in C++. UUserWidget is one of those classes and those reside in UMG module not Slate, so you need to add UMG dependency in to it. Slate and SlateCore is also needed there as there some types used in UMG functions are from those modules, most commonly FSlateBrush or FSlateColor.

For more, please provide logs from Output tab. Also do you do proper includes?

Hello ,

After adding the “UMG” dependency module to my PublicDependencyModules it works perfectly fine! Thanks alot :slight_smile:

If you have any linker errors go to API reference of referenced function or class and look below the page and it will show you module name that this function or class is in and you need to add to dependency:

UE4 has al ot of modules and some have very materialistic functions, so you might find to need unexpected module, for example GameplayTags has there own dedicated module for just support of single type. So it’s good to know where to fins in which module they are in

Aaah, I wasn’t aware of this. That’s very useful!