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"

Passing Variable

Hello. Emm.. I know this is quite... basic stuff but I just can't figure out how to make it work.

I have my HUD class, and my GameMode class. On the GameMode class I have a variable (int), which it's value will change eventually, and I want THAT variable to get printed/drawed on my HUD, the problem is that I can't figure out how to pass that variable.

I've included the .h file, creating object pointers and that.

Thanks

Product Version: Not Selected
Tags:
more ▼

asked Apr 10 '15 at 04:21 AM in C++ Programming

avatar image

Georgespartan01
192 19 23 80

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

2 answers: sort voted first

With c++ you can create a UBlueprintFunctionLibrary class, and make a global function to return that GameMode variable, you can use this blueprint function anywhere u want, this my code to get the GameModeType for my game then use it in HUD to display what gamemode i'm in

Declare in header:

 UFUNCTION(BlueprintPure, Category = "GameMode", meta = (WorldContext = "WorldContextObject"))
 static TEnumAsByte<EGameModeType> GetCurrentGameMode(UObject* WorldContextObject);

in cpp:

 TEnumAsByte<EGameModeType> USUBlueprintFunctionLibrary::GetCurrentGameMode(UObject* WorldContextObject)
 {
     if (!WorldContextObject) return EGameModeType::GAMEMODE_NONE;
 
     UWorld* const World = GEngine->GetWorldFromContextObject(WorldContextObject);
     if (!World) return EGameModeType::GAMEMODE_NONE;
 
     //Get GameMode if is Server
     AShooterGameMode* GM = Cast<AShooterGameMode>(World->GetAuthGameMode());
 
     //Get GameMode if is Client
     if (GM == NULL)
     {
         GM = Cast<AShooterGameMode>(World->GetGameState()->GetDefaultGameMode());
     }
 
     if (GM == NULL) return EGameModeType::GAMEMODE_NONE;
 
     return GM->GameModeType;
 }

UPDATE: Sorry i thought u want to use in blueprint, You can still use my code the part where you get the GameMode, you can use GetWorld() through HUD class GetWorld() or use GEngine->GetWorld() for anywhere, from GetWorld() u can get GameMode like above.

more ▼

answered Apr 10 '15 at 07:57 AM

avatar image

Duncan Dam
3.1k 121 50 164

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

THANKS! I knew I needed to use the Cast Template, Im not very familiar with it. Your code is very useful BTW, It seems passing variables between classes is not an "easy task" as I thought it was.

more ▼

answered Apr 10 '15 at 03:28 PM

avatar image

Georgespartan01
192 19 23 80

(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