Can't reference a variable from another blueprint

Hi all,
I’ve got a little problem, when I’m trying to reference a variable from another blueprint runtime (the blueprint I’m referencing is the actor, and this is a progressbar on the hud) it can’t get it’s value. When I ask it’s value it shows it is equal to 0.
There are no errors, no warnings(in the designer and runtime both), the only thing I see is that the value does not change, it changes in the original blueprint, but this cannot get it’s value. That’s really strange, I never had this problem before.
Here’s my blueprint:

Thanks in advice

Hi ,

You need to do a cast to your other blueprint to get the variable. Check here for additional information on casting and blueprint communication:

https://docs.unrealengine.com/latest/INT/Engine/Blueprints/UserGuide/CastNodes/index.html

Thank you for your quick reply, but what do i connect to the object parameter? I’m referencing a blueprint actor that contains only a light (which places trace lines but that’s not important).

I try from a different approach, i modify the percent from the actor bp

Now i have no idea, i tried casting with no success, no errors runtime, no errors while compiling, but the value still remains 0. Any helps would be greatly appreciated.

Can you post a screenshot of what you are doing? Where are you calling GetPercent?

I’m calling the get percent in the hud’s progressbar’s binding.

And by the way i sat a breakpoint and the value doesn’t change, so the error is not with the progressbar, it’s with the blueprint itself, i mean the binding. The blueprint I’m calling the variable from is working correctly, giving the value I specified for it. But this one doesn’t do anything. Thanks in advice

Okay, I post a screenshot of my BP (not the binding, the binding is the one up at my Question)

So please help me. Any helps would be greatly appreciated.

It’s pretty clear that something goes wrong in the Cast To MyHUD1 nodes. If you have a look at the Compiler Results, you’ll probably find a warning that “casting will always fail” or something along those lines.

What this means is that the GetHUD either returns nothing or a different HUD class than your own one.

Did you set MyHUD1 as your default HUD in your GameMode Blueprint?

Thank you I’ll check it out

Hi I checked it, and it is not set as hud, but I don’t understand why I can’t set it as hud, it does not appear in the drop down menu. btw it’s a widget blueprint, but in a video tutorial they showed it should work. I had done hud in an earlier project and I didn’t have any issues with it. Any Ideas?

Or wait, the Hud itself (my widget bp) appears, but the progressbar is empty all the time. Does not change. I added breakpoint and realised the blueprints cannot communicate. Any advices?

If your “hud1” is a widget then casting from the “get hud” node won’t get your widget. What you need to do is, where you create the hud/widget (I usually create all my widgets in the controller cause it’s easy to get) save its instance to a variable. If you do this in the player controller then Get Player Controller, cast it to your custom player controller then you can draw off its output pin to get your “hud1” or widget blueprint reference/variable. If you don’t have a custom HUD BP (not a widget, actual HUD) then just leave your game mode setting as “HUD”.

If your “light 1” object in your original picture is not an object in the widget, you need to cast it to you BP that is the “light 1” object BP or, what I’ll do occasionally is when the “light 1” BP is spawned, in event begin play of its Graph, if I need an instance of it set elsewhere, like you do in your widget, have it get your reference to the widget (as I said above) then have it set that variable in your widget to itself. That way there is no need to cast to the “light 1” BP inside your widget cause you just set it when the BP was created.

Thank you for your answer, I don’t understand it fully, maybe my bad english, but what do you mean with saving the instance to a variable? Do you mean should i create a reference for it in the Light1? Can you explain it or link a tutorial please?(I mean for the thing you said)

So just answer what did you mean with saving instance to variable.

Yes it means to save a reference to a variable. Every time you spawn or create an object into the world that is called an instance of that object. Even if it’s the same BP spawned over and over, each one is its own “instance” of that BP. If you spawn the light 1 into the world from from your player controller then save the reference to a variable in the player controller because the player controller is easy to get from any other BP by calling “get player controller” and casting to your custom controller.

Thank you this worked, I don’t know I did the thing you said exactly, but the theory successfully worked. I mark it as answer.

thank you, I give it a try