Download

C++ Widget

Hello,
I am trying to make a Widget class and i am getting an error
header file


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

#pragma once

#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;

    //float GetHealth();

    UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
    class UProgressBar* HealthProgressBar;


};

.cpp


#include "PlayerUserWidget.h"

UPlayerUserWidget::UPlayerUserWidget(const FObjectInitializer& ObjectInitializer)
{

}

void UPlayerUserWidget::NativeConstruct()
{
    Super::NativeConstruct();
}


if some one can tell me why i am getting this error:
Error C2512 ‘UUserWidget’: no appropriate default constructor available
that would help me a lot.

You get that error because UUserWidget has no default constructor that takes in nothing. So, since your class inherits from UUserWidget, you need to call the appropriate constructor.


 
 UPlayerUserWidget::UPlayerUserWidget(const FObjectInitializer& ObjectInitializer) : UUserWidget(ObjectInitializer) {  } 

Thanks man that was it :slight_smile: