Download

C++ Widget

Hello,
i am new to unreal engine and tried to make a widget class.
I made a blueprint out of the widget but i cant find the designer button.
Can any one show me how to open the designer?
I am using UE 4 Version:4.23.1

Widget.h is the base class without the designer. You need to derive from UserWidget.h to get the designer.

If you make a widget derived from Widget.h in C++ then you can still add it in another Widget Blueprint but you won’t get a designer to modify it.

but i am deriving from UUserWidget
header file:


#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "Runtime/UMG/Public/UMG.h"
#include "PlayerUserWidget.generated.h"

/**
 * 
 */
UCLASS()
class LOST_API UPlayerUserWidget : public UUserWidget
{
    GENERATED_BODY()

public:

    UPlayerUserWidget(const FObjectInitializer& ObjectInitializer);

    virtual void NativeConstruct() override;

    void UpdateComboCount(int32 Value);

    void ResetCombo();

    UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
    class UTextBlock* TXTCombo;


};

Hello,
i think you need to initialize it

virtual bool Initialize() override;

bool UPlayerUserWidget::Initialize()
{
bool bInit = Super::Initialize();
return bInit;
}

I have added it and it didn’t work
Any other advice?

Try to change this:


 
 UCLASS() class LOST_API UPlayerUserWidget : public UUserWidget 

To this:


 
 UCLASS(BlueprintType, Blueprintable) class LOST_API UPlayerUserWidget : public UUserWidget 

Also do not override functions if you just call their super functions as good practice.

That didn’t work as well :frowning:

Can you tell me why ?

I also had this problem, I think it’s a known issue if you inherit the UserWidget from a C++ class.
What I do is:

  1. Create a UserWidget from your Content folder: Right click -> User Interface -> Widget Blueprint
  2. Create a C++ class inherit from UserWidget.
  3. Change the UserWidget blueprint Parent Class to your C++ class.

This is a little unnecessary overhead as it does nothing different from what the base class already does. So you can remove you Initialize() method.

The workaround does do the job thanks :slight_smile:
But it is kinda weird they didn’t fix it.

You can create a WidgetBlueprint and THEN use reparent to reference your c+ widget

i have a problem trying to create a custom widget.
i have this code.


static ConstructorHelpers::FClassFinder<UUserWidget> MenuClassFinder(TEXT("/Game/Blueprints/UI/WBP_Gameplay"));

    if(!MenuClassFinder.Succeeded())
    {
        UE_LOG(LogTemp, Error, TEXT(" USGameplayWidget !UITmp.Succeeded() "));
        return;
    }

    TSubclassOf<class UUserWidget> MenuClass = MenuClassFinder.Class;


    USGameplayWidget* Menu = CreateWidget<USGameplayWidget>(this, MenuClass);

but i get the error


Severity    Code    Description    Project    File    Line    Suppression State
Error    C2338    CreateWidget can only be used to create UserWidget instances. If creating a UWidget, use WidgetTree::ConstructWidget.    CastleVersus    C:\Program Files\Epic Games\UE_4.23\Engine\Source\Runtime\UMG\Public\Blueprint\UserWidget.h    1420    


this is the code of my custom widget


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

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

/**
 * 
 */
UCLASS()
class CASTLEVERSUS_API USGameplayWidget : public UUserWidget
{
    GENERATED_BODY()

};


The error was because i missed to include USGameplayWidget.h and only added the forward declaration of the class