Hi!
I have trouble understanding how I should implement main menu screen in my game, using both c++ and blueprints and make best use of the engine.
Right now I have implemented my main menu as mentioned below:
-
I created UserWidget blueprint class (so it would be easy to design it there)
-
As my whole project is based on c++, I also created HUD class, that´s associated with my gamemode class
-
Now I created an instance of UserWidget in my HUD class based on the blueprint I created and set it up
------------------------.h file --------------------------------
UPROPERTY(EditDefaultsOnly, Category = ComponentClasses)
TSubclassOf<UUserWidget> MainMenuWidgetClass;
UPROPERTY(BlueprintReadOnly, Category = Components)
UUserWidget* MainWidget;
------------------------.cpp file --------------------------------
MainMenuWidgetClass = StaticLoadClass(UUserWidget::StaticClass(), nullptr,
TEXT("/Game/2DSideScrollerCPP/Blueprints/Menu/MainMenuWidget.MainMenuWidget_c"));
------------------------.cpp file widget to viewport --------------------------------
MainWidget = CreateWidget<UUserWidget>(GetWorld(), MainMenuWidgetClass);
MainWidget->AddToViewport();
GetOwningPlayerController()->bShowMouseCursor = true;
Now when I press on the button in my widget blueprint, the event will fire and I call the UFUNCTION exposed function based on the button. But the example logic looks like this (note that Start Game function is the exposed function at the moment):
It seems to me that I might be doing this a bit wrong (what I mean is the workflow). Maybe there are some good practices that I could take in count when I create the main menu or you have experienced some better workflows during creating UI. I would very much appreciate every advice. Thank you in advance!
Best wishes