How can I hold values in an interface, change them, and have them update other blueprints?

I’m not really sure how the interfaces work. I want to hold values in a interface then change them and have them update in other blueprints.

Right now I am making a energy bar for when the player Jetpacks, I have it set to drain energy from the interface I made and the hud reads that and draws the energy bar. When I try to drain it doesn’t effect the hud. How do you hold a value somewhere and then have it change in multiple blueprints? It doesnt seem to change the interface value, and I don’t understand how the interface works.

1st screen is my hud, 2nd screen is my character where the energy drains and should show up on the hud, 3rd screen is the interface, also i have an output in the interface for no reason, because I don’t understand what it does can you explain input and output?

7855-2.jpg

First, you have to go to the blueprint props of your HUD blueprint. In the properties menu you must add the interface blueprint to the list of implemented interfaces.

After compiling your HUD blueprint your should have an Event node with the name ‘PlayerHealthEnergy’ available in your HUD blueprint. Every time your call the function ‘PlayerHealthEnergy’ in one of your blueprints, the event node in the HUD is executed. (Note: your have to give a reference to your HUD Blueprint as the target pin input. You can get the reference by calling the ‘Get Player controller’ node and putting the output of that node in the ‘Get HUD’ node.)

To actually transfer parameters to your HUD blueprint you have to add the corresponding input pins to the interface function in the interface blueprint.

If you are still confused when I get home I can upload a picture of a very simple example.

EDIT:
Here is an example:
This is how your interface blueprint could look like.

This is how your jetpack instance (or whatever) could look like:

Since I cannot put more than two pictures in the answer I will continue in another post…

yeah where I’m stuck at is the input pins. I tried changing their values from another blueprint but they don’t seem to change the interface values. Also whats the purpose for output pins? Also a picture would help. Finally I HAD to do set the input pins to pass by reference to hook them up to other variables. even tho they were floats they wouldn’t hook up to other floats on functions. Why is that? They did when I did pass by reference.

…continue example…

Your HUD needs to add the interface:

Your HUD event graph could look like this:

This would draw a very basic HUD that gets the current health and energy values from your jetpack blueprint every tick and draws both values in the top left corner of the screen. (Right on top of each other but the principle should be clear :slight_smile: )

For this application your don’t need the interface output pins. These would be needed if your HUD would do something with the values, for example checking whether you clicked on a HUD element to refill those values, and than return those modified values to the jetpack blueprint to update the values as well.
(Note: if your interface returns something, the event node won’t show up. Instead a function is added to your HUD as soon as you add the interface blueprint.)

Why you need to pass those values by reference I can’t answer you. I did not experience this problem before.

I’ve also been trying just referencing blueprints in general. I think the problem is I have the Health In mycharacterblueprint. When I try to find all actors of that class it turns to an array but i cant cast to the player controller. It doesn’t accept a input. The only CASTTO available is playercontroller. Which isn’t an object, its a player controller.

Man I’m sorry to ask you a bazillion questions but for some reason in your last picture you have Event PlayerHealthEnegy. This isn’t showing up as available even with context off, in the hud class. I added it as a interface like you said to do, in properties. It does show up as a function like in picture # 2, but not as a event.

This PlayerHealthEnergy Event isn’t anywhere to be found.

I am not sure what you mean but I will try:
You should always have one PlayerController instance. The one defined in your Gamemode. If you have several instances of the same character blueprint and only want the health/energy values from the one you are currently controlling, you could use the ‘Get Controller’ node and check if the controller of that object is equal to the ‘Get Player Controller’ return value. If they are equal, you call the interface function, otherwise you don’t.

Is that an answer to your question?

EDIT:
To your second comment:
The node only shows up in the ‘Event Graph’ not in any other blueprint function. Maybe that is the problem. Or maybe, if you defined an output for the interface, adding the interface automatically adds a function to your HUD blueprint. In that case you won’t get the event node as well.

Sometimes it might also help to restart the editor.

PS: I had a very rough start myself when I started using UE4 a few weeks ago. Asking questions is fine.

Yeah it’s just loading as a function and i cant set update health to the Health parameter in the interface.

I tried restarting, I still only get this function.

I’m going to try restarting my computer, could the problem be I am on 4.1.1? instead of 4.2?

This feature was also available in 4.1.1.
Are you sure you added the interface to your HUD blueprint not to your character blueprint? The interface must be added to the blueprint that is supposed to recieve the event.
Or maybe you did not press ‘compile’ in your HUD blueprint after adding the interface.

That are the only reasons I can think of right now.

Ok I found it. It was just some bug where I couldn’t find it by searching after you right click, to look for something. I was looking for Player and it was ONLY showing the function but I found it by right clicking and then going through the sub menus. Now it works. Thanks a LOT!

Maybe not showing up if you have it inside of a function, rather than the eventrgaph of the particular blueprint. Events can’t go inside functions.