Trying to pass a string from the Map to the HUD

Hi Guys,

I’m working on a HUD and I’ve run into some trouble getting my score to display. At the moment I have two integers in my Third Person Example Map, RedScore and BlueScore. I take both of these and append them into one string S_Score. I’m trying to pass this string to my Widget Blueprint where it will be displayed, but I can never find the string despite it being set to public.

Can anyone help?

By “Map” I assume you mean level blueprint? As far as I know, there’s no way to access variables in your level blueprint from other blueprints (see here)

You could make it so your level blueprint has a reference to your created widget, and then assign the S_Score to some other string in your widget.

Personally, I’d recommend using your GameMode or player Pawn/Character for storing your S_Score variable as those blueprint instances are accessible and castable from anywhere.

Hi, thanks for the reply. Yes I do mean Level Blueprint when I say map. I’ve been trying to get the method you suggested working; create a variable in the Game Mode or Third Person Character Blueprint, then use the existing score variable in the Level Blueprint to set that new variable. Each time I try I end up needing to cast and cannot find anything the supply to the Object node.

For instance, using a variable created in the Third Person Character Blueprint. The problem here is that I’m required to plug something into the Object pin on the Cast To ThirdPersonCharacter; I spawn my character rather than have it existing in the Level before play is hit, so how would I get the Object I’m supposed to be plugging in?

There are several ways to get your ThirdPersonCharacter from any other blueprint (inluding your level blueprint).

You can do GetAllActorsOfClass (this will return an array with all actors of the specified class; just iterate through your array and find your character). I don’t recommend calling this method every tick as it’s performance intensive.

OR

If your ThirdPersonCharacter is currently being controlled by a player controller (ie, you’re controlling it), you can GetPlayerController, and from that player controller you can GetControlledPawn. Plug that pawn into your “Cast To Third Person Character” node and you’re done.

If you we’re to store you score in your game mode instead, it’d be a bit more straightforward as you can just call GetGameMode and cast that to your game mode.

Hope that helps.