I am trying to cast to MyCharacter from my HUD

Hi,

I am trying to cast to MyCharacter in order to retrieve the gamescore variable for my game from my HUD blueprint. I have the following so far (see attached picture)

19585-capture.jpg

So basically I am getting the printed string Score to HUD failed. I think this is related to the object in cast to Mycharacter. I do not know what to give it.

Could someone give me some insight on this? It’d be very appreciated.

Right Mouse Click - > GetPlayerCharacter → Cast To MyCharacter

Thank you for your help. However, it still returns a null (0) value. I have the game score value to be set to 10 with an event begin play in the MyCharacter blueprint (so it should give me a result of 10).

19587-capture.jpg

Your HUD should only be displaying the score. The math, for adding or subtracting from the score, should be done on a separate Blueprint like the Game Mode or Character Blueprint. Then, you simply cast the score from there to the HUD, or whichever Blueprint needs the info.

You need to cast the score variable from your MyCharacter BP to your HUD. That way, your MyCharacter BP does all the math, and your HUD just displays it. There isn’t any need to cast from the HUD. I did a quick mockup below.

The Level Blueprint adds 1 to the variable ScoreVar each time I press the F key. It then Casts that result to the HUD. The HUD Blueprint then draws the score to the bottom right of the screen. Everytime I hit the F key, it updates. Does this help?

I understand. It is another blueprint indeed that adds/substracts. So the casting node should be in MyCharacter instead of in the HUD blueprint that needs the info?

As of now I have three blueprints:

MyCharacter
Hamburger
HUD

In the hamburger blueprint, it gets the score from MyCharacter, then casts it back to MyCharacter. Where I block is at the part when the HUD is supposed to get that changed value from MyCharacter and display it on screen. What you’ve seen in the screenshots is the HUD blueprint.

Again, thank you for helping me with this.

This does help. I am having a problem creating the last node on the right in the event graph of example map. Apart from that, I think I understand the logic more.

So how were you able to create the set node on the right? (With ScoreVar (or in my case, gamescore) and target? :slight_smile:

EDIT: I was able to create the missing node. Right now I have an error because my HUD blueprint isn’t a canvas.

Once you get the Cast To HUD node you just pull off the blue As HUD_C pin and search for your variable (gamescore) and set it. :slight_smile:

Make sure you derive your HUD BP from the HUD class. Example Below.

Great. My blueprint is derived from the HUD class. I’m trying to see if the issue is elsewhere. Any other idea on what could be causing this issue?

*Again, thank you :smiley:

Apart from that, I tried with a print string and the value is cast correctly to the blueprint HUD and does modify accordingly to the objects I collect. So the issue really is just with the draw text

Great! Everything is working perfectly. Weird xD I had to create a new draw text node from the right click and it did solve the issue.

Many thanks. :slight_smile:

Try deleting that draw text hud, then right clicking anywhere in the HUD BP and pull up a new Draw Text. I’m not sure how, but that Draw Text Node you are using is targeting the Canvas and not your HUD. Notice your Draw Texture node says Draw Texture and Target HUD beneath that, it should be the same for your Draw Text.

Your welcome! :slight_smile: