widget displaying variable as 0

Hi,

I’m struggling with what should be a really easy thing to do and I’ve done similar things without trouble.
All I want to do is display a variable (a float health value) of an enemy. I have a healthbar for it and the health calculations all work fine etc so I’m curious why all I get is ‘0’

Here’s one thing I tried:
bme_health

I’ve also tried Set Text in the Event graph of the widget to grab it using an Actor reference too, and that displays as ‘0’.

Anybody got an idea please?

Thanks,
Daz

Try other variables that are inside of your BME_Ref.

  • Are all variables the default or just max health?
  • Where are you setting the BME_Ref?
  • Are you destroying the actor referenced by BME_Ref after setting it?

Hey, it seems to be all the variables.

I create the reference to the BME actor inside the widget itself, as I’m sure I’ve done with other times I wanted to reference another actor from somewhere other than itself?

This is my other attempt I talked about, with setting it in the Event Graph of the widget:
bme2

I just get ‘0’.

I know it’s something ridiculous I’m doing and I’ll kick myself, but I can’t figure what!

Daz

I don’t understand what you mean by “I create the reference to the BME actor inside the widget itself”.

Does the actor exist in the level?

If so, where are you setting it’s reference to be the BME Ref in the widget?

Simply having the BME Ref in the widget is not enough. If you’re spawning the BME Ref in the widget then your game is not actually updating the proper BME.

So, if you’re spawning the BME inside the widget, and not updating the variables for it, then you will never get anything other than default values.

I had the exact same problem when trying to count actors in the level and print it to the HUD. I found when trying to get variables to my HUD that widgets really don’t like interacting with things that aren’t the player. So the workaround I managed to do was to:

138481-thestorage.png

  • Set the variable in the Player Character/Camera Pawn Controller blueprint (You don’t have to get it like the picture, that’s just to reference where I created it)

  • Cast the object setting the number to the PC/CPC and set the variable from there

  • Create a binding for the Text you want to display on the HUD, then inside that cast it to the PC/CPC, retrieve the value, then convert it to text

Hope that helps!

Hmm. The BME actor reference is referencing a Blueprinted actor, which get randomly spawned and placed at runtime, therefore I have no static, placed version in the level to reference. I thought making a reference to the blueprint within a widget would grab any instance of it and apply the logic (seeing as each of the BME actors has a Healthbar widget attached to them).

Maybe a better thing for me to ask is how would you achieve what I am talking about doing, rather than trying to work out what I’m doing wrong?

I guess whats lead me down the wrong path so to speak is that I grab the values of those variables no problem when applying to the progress bar for the health widget, but when I want to print them on screen above the healthbar of the BME actor during game, I just get zero rather than the values and I was doing the same thing!
Urghh. my head hurts

Thanks, I will try a similar setup with my stuff later when I’m home.

Do we have any idea why it’s so easy to cast to the player character from anywhere, but when it comes to casting to anything else there is nothing to plug into the ‘Object’ pin? This is why we have to create references and I find it confusing sometimes.

If we can do it for the player with the use of ‘get Player Character’ etc then it seems there would be a way to use a ‘Get AI Character’ (perhaps from an array you create or something?) as well?

Anyway, I’m sure there are good reasons why from a technical point of view but it’s such a pain that everything is so easy when it’s to do with the Player, but such a pain when it’s anything else!

Thanks,
Daz

It does not matter when your actor is spawned (whether at runtime or static in the level) provided you pass the right reference to your widget.

Widgets are owned by player controllers. Other actors may reference them.

So, if I wanted a HP display on a widget that was based off of something I spawned, I would first spawn the actor (in your case a BME actor) then create the widget and assign the BME ref (found inside your widget) to the actor I just spawned. That way my widget would have a valid working reference to the proper BME actor I have spawned in the level.

Here’s how it would look:

There isn’t a wealth of information about Casting about, but the closest guess I have is that it comes down to controllers and how they would work in the subject code. A “Player Character” can have an object that owns it, like a Controller, so it can be cast to it quite easily as lots of things can take control of it. Something less controllable, like a static level object or a HUD doesn’t really have anything that can take control of it or do anything with it, so the things that can cast to it are limited. Get AI character does work with it, for the record, but the recipient has to be capable of being an AI character, if that makes sense.

That is only guesswork from playing around with it though - I’m sure someone with a stronger base knowledge in code could explain it better!