How to pass a value from one BP to a different BP

Hello,

Let me start by saying that I am very new at this, but I am willing to learn. In short teach me, and I will listen.

I have a very simple game, a green ball and red ball are in a closed arena, the player controls the green ball, and chases the red ball. When the player hits the red ball, I would like the score drawn on the screen.

I think I have all this setup correctly, however I am failing at getting a value passed to my HUD BP. Attached are some .PNGs of what I currently have, I look forward to finding out just how far off the mark I am.

Let me know if you need more information, and thank you for your time,

Jeff

It seems to me that your log is saying that “TargetRefEmenyBP” is null. In your HUD BP, do you ever set that reference to your enemy?

If I’m right and you need to set the reference to your enemy, you might find this useful to have a look at.

Let us know if that helps!

I think I have. Attached is a .PNG of the details panel of “TargetRefEmenyBP”.

However, the second part of the link you referenced “Specifying the Blueprint Instance” I have not done. I cant seem to get the HUD_BP to display details in the Level Editor. I suppose I should have mentioned that in my first post, sorry. I have also attached a picture of the Level Editor, with the HUB_BP selected and empty details panel. Perhaps I missed something there?

Thanks again!
Jeff

Yes, HUD_BP is descended from the HUD class, and I’ve set it to be the HUD in the game mode. Is that not the correct way to handle this?

I don’t quite follow what you mean, here is what I have done so far. I am sure I am off the mark, see attached.

Thanks,

Jeff

So your HUD BP is descended from the HUD class, and you’ve set it to be the HUD in the game mode, so I guess it doesn’t appear in the level editor?

I think what I’d do in this situation is get the HUD from the enemy BP, so maybe on Begin Play do this:

Then set the enemy reference in the HUD you just got to “self”. It’s a bit circular, (your enemy now needs to know about the HUD, and the HUD knows about the enemy) and there is almost definitely a better way to do this, but I think that’s what I’d do.

No, that’s fine, I was just checking for my own sake. I’m not so good with HUDs and widgets, so I wanted to be certain :slight_smile:

You’re almost there: now you’ve got the HUD when your enemy spawns, you should be able to drag a pin off of the “As HUD BP” and there should be a node for Set TargetRefEmenyBP that appears in that list. Use it, passing in a self reference.

Just as information, what we’re doing here is, when the enemy spawns, it grabs the HUD instance associated with player 1 (or zero - I have no idea how multiplayer works), and we’re setting the enemy that that HUD requires to be the one that just spawned.