“no default constructor exists for class ”UUserWidget“”

I have experienced a strange issue writing the constructor of UUserWidget-inherited class. The problem appears only (checked in several other) in this class. Code: .h .cpp UserWidget.h

2 Likes

Did you add the dependencies from UMG and Slate in your Build.cs file?

Yes I did.

Ok I have solved the issue.

Thanks for your answer.

2 Likes

Oh, right! I hadn’t noticed you were not calling the constructor of the parent class. You should mark you answer as accepted so others can find it in the future.

The solution:

As @vr_marco said: I had to “call the constructor of the parent class”.

1 Like

Why? Why does this need to be done? Under what circumstances does this happen and why?

Im wondering the same thing. All this stuff is so poorly documented …

This is not unreal specific, that’s C++ behavior

basically, you need to do it in any case where the constructor of your base class needs data that you hand in from the child constructor.

In that case, what happened is that if you don’t call a parent constructor the default constructor was being called and the parent class doesn’t have one, which leads to the error

For example:

FObjectFinders can’t be used outside
of constructors to find
/UI/Icons/home-outline

1 Like
UMainMenu::UMainMenu(const FObjectInitializer&Object):Super(Object)
{

	ConstructorHelpers::FClassFinder<UUserWidget> ServerWidgetClass(TEXT("'/Game/UI/MenuSystem/WP_Server'"));
	if (ServerWidgetClass.Class)this->ServerWidget = ServerWidgetClass.Class;
};

in my case, this had served me to load assets for my widgets…