Download

No appropriate default constructor available error

So i have this code



Main_HUD.h

#pragma once

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

class UCanvasPanel;

UCLASS()
class GAME_API UMain_HUD : public UUserWidget
{
    GENERATED_BODY()

protected:
    UCanvasPanel* CanvasPanel;

    UMain_HUD();

};

Main_HUD.cpp

#include "Main_HUD.h"
#include "Components/CanvasPanel.h"

UMain_HUD::UMain_HUD() { //this is the line that the error points to
    CanvasPanel = CreateDefaultSubobject<UCanvasPanel>(TEXT("Canvas Panel"));
}


And i get this error:
‘UUserWidget’: no appropriate default constructor available

Any ideea?

1 Like

No default constructor means exactly that, the class you are inheriting from needs you to specifically call a constructor.

Try:



UMain_HUD::UMain_HUD(FObjectInitializer& ObjectInitializer)
: UUserWidget(ObjectInitializer) // Call the UUserWidget's constructor.
{
    CanvasPanel = CreateDefaultSubobject<UCanvasPanel>(TEXT("Canvas Panel"));
}


3 Likes

Well, the code now compiles. Thanks.