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"

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) alt text

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.

Product Version: Not Selected
Tags:
capture.jpg (49.0 kB)
more ▼

asked Oct 30 '14 at 09:06 PM in Blueprint Scripting

avatar image

Madvoyer
101 15 18 25

avatar image ThePassenger Oct 30 '14 at 09:24 PM

Right Mouse Click - > GetPlayerCharacter -> Cast To MyCharacter

avatar image Madvoyer Oct 30 '14 at 09:30 PM

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).

alt text

capture.jpg (46.5 kB)
avatar image Counterpart0 Oct 30 '14 at 09:34 PM

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.

avatar image Madvoyer Oct 30 '14 at 09:42 PM

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?

avatar image Madvoyer Oct 30 '14 at 09:45 PM

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.

avatar image Counterpart0 Oct 30 '14 at 11:21 PM

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. :)

avatar image Madvoyer Oct 30 '14 at 11:38 PM

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 :D

alt text

capture.jpg (87.3 kB)
avatar image Madvoyer Oct 30 '14 at 11:42 PM

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

avatar image Counterpart0 Oct 30 '14 at 11:57 PM

Your welcome! :)

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

2 answers: sort voted first

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. alt text

alt text

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?

level_bp_score.jpg (40.3 kB)
hud_bp_score.jpg (35.3 kB)
more ▼

answered Oct 30 '14 at 10:10 PM

avatar image

Counterpart0
14 10 9 11

avatar image Madvoyer Oct 30 '14 at 11:08 PM

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? :)

avatar image Madvoyer Oct 30 '14 at 11:18 PM

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

avatar image Counterpart0 Oct 30 '14 at 11:28 PM

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

derived_hud.jpg (89.9 kB)
(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Oct 30 '14 at 11:46 PM

avatar image

Counterpart0
14 10 9 11

avatar image Madvoyer Oct 30 '14 at 11:53 PM

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. :)

(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