x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Get GameMode

I have looked everywhere trying to figure this out, along with playing with code trying to get it to work. Might be really simple and i am just looking too much into it. My goal is to call a function from my game mode in my HUD class ie. trying to figure out how to change HUDs while game is running.

Question: "How do you get the current GameMode and set it to a pointer so i can call my function?"

Note: I am calling this from a custom SCompoundWidget class. Goal is to call my function in my game mode from a button click and it will set the HUDClass variable of GameMode to a different HUD class.

Product Version: Not Selected
Tags:
more ▼

asked Oct 18 '14 at 10:52 AM in C++ Programming

avatar image

ErraOfWar
15 6 8 8

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first
more ▼

answered Oct 18 '14 at 01:52 PM

avatar image

TimGS
621 20 23 236

avatar image ErraOfWar Oct 18 '14 at 04:31 PM

Well that seems to create the pointer I needed, but now I have another issue. For some odd reason the game mode won't update the class and display it.

In my custom SCompoundWidget class i have this as my button click function:

 FReply SMainMenuUI::PlayGameClicked()
 {
     MenuHUD->PlayGameClicked();
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, TEXT("PlayGameClicked"));
     TObjectIterator< APlayerController > ThePC;
     UWorld* TheWorld = ThePC->GetWorld();
     ATarragonGameMode* MyGM = Cast<ATarragonGameMode>(UGameplayStatics::GetGameMode(TheWorld));
     MyGM->SetHUD("Login");
     return FReply::Handled();
 }

Then in my GameMode i have this function:

 void ATarragonGameMode::SetHUD(FString MenuName)
 {
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, MenuName);
 
     if (MenuName == "MainMenu")
         HUDClass = AMainMenuHUD::StaticClass();
     else if (MenuName == "Login")
         HUDClass = ALoginHUD::StaticClass();
 
 }

When i click the button on my MainMenuHUD which the PlayGameClicked function is linked to. It displays the text "PlayGameClicked" and "Login" so it goes into the correct functions, but HUDClass won't update and show my LoginHUD.

Any Suggestions?

avatar image TimGS Oct 18 '14 at 07:27 PM

I don't think you can change default HUD class during runtime (I may be wrong, devs will correct) and more appropriate way to change your current hud class for player is to use APlayerController::ClientSetHUD() function.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question