I understand using a setter like this is good practice:
void UMainMenu::SetMenuInterface(IMenuInterface* MenuInterface)
{
this->MenuInterface = MenuInterface;
}
But the solution I found on my own was this:
bool UMainMenu::Initialize()
{
--Some other code--
MenuInterface = Cast<IMenuInterface>(GetGameInstance());
return true;
}
To my understanding these both essentially do the same thing. My question is what is the advantage of using a setter that has to be called from the game instance when it could just be set from the main menu code without ever having to touch the GameInstance’s code other than having it derive from IMenuInterface and adding necessary functions?