Mismatch between CreateWidget and MenuClass/FClassFinder

@ 2:38 in the video, Sam changes the CreateWidget call to instantiate a UMainMenu object instead of a UUserObject.

However, he does not change the call to FClassFinder. So Unreal will be perfectly happy to assign a non-UMainMenu class to the game instance.
Similarly, in the header MenuClass remains a TSubclassOf<UUserWidget>. This one is less important to update if the constructor does the right thing. However for consistency and self-documentation, it ought to be updated as well.

The code will still work if the source is not updated since it checks the results of CreateWidget (which will be nullptr if the class is some other kind of UUserWidget than a UMainMenu).
The main drawback is that the first error will happen in LoadMenu instead of the constructor, which will makes pinpointing the source of problem a bit harder.


In summary, in the PuzzlePlatformsGameInstance.h header, we should have:

TSubclassOf<class UMainMenu> MenuClass;

and in the PuzzlePlatformsGameInstance.cpp, we should have:

UPuzzlePlatformsGameInstance::UPuzzlePlatformsGameInstance(const FObjectInitializer & ObjectInitializer)
{
	ConstructorHelpers::FClassFinder<UMainMenu> MenuBPClass(TEXT("/Game/MenuSystem/WBP_MainMenu"));
	...
}

Privacy & Terms