Why I have to do it like this

In this version of unreal why I have to do my menu construct like this :

UMainMenu::UMainMenu(const FObjectInitializer & ObjectInitializer) : Super(ObjectInitializer)
{
	ConstructorHelpers::FClassFinder<UUserWidget> ServerRowBPClass(TEXT("/Game/MenuSysytem/UI/WBP_ServerRow"));
	if (!ensure(ServerRowBPClass.Class != nullptr)) return;

	ServerRowClass = ServerRowBPClass.Class;
}

instead of like this as we do normally :

UMainMenu::UMainMenu(const FObjectInitializer & ObjectInitializer)
{
	ConstructorHelpers::FClassFinder<UUserWidget> ServerRowBPClass(TEXT("/Game/MenuSysytem/UI/WBP_ServerRow"));
	if (!ensure(ServerRowBPClass.Class != nullptr)) return;

	ServerRowClass = ServerRowBPClass.Class;
}

I was doing in the normal way as we have done always but I get errors :

UMainMenu::UMainMenu(const FObjectInitializer & ObjectInitializer)
/Users/zkc08/gd/unreal project/SteamMultiplayer/UnrealProject/PuzzlePlatforms/Source/PuzzlePlatforms/MenuSystem/MainMenu.cpp:13:12: error: constructor for 'UMainMenu' must explicitly initialize the base class 'UUserWidget' which does not have a default constructor

after few days now I finally used the method above which uses UMainMenu::UMainMenu(const FObjectInitializer & ObjectInitializer) : Super(ObjectInitializer).
Please explain why I need to do things like this?

The second one is using FObjectInitializer still.

It’s either

// .h
class UMainMenu
{
    UMainMenu(const FObjectInitializer & ObjectInitializer);
};
// .cpp
UMainMenu::UMainMenu(const FObjectInitializer & ObjectInitializer) : Super(ObjectInitializer)
{
}

or

// .h
class UMainMenu
{
    UMainMenu();
};
// .cpp
UMainMenu::UMainMenu()
{
}
1 Like

Means I could have done easily without writing
FObjectInitializer