So I’m learning Blueprints, and I have a communications question about using BP Interface.
TDLR
How do I update the UI based on whichever actor the character is interacting with using BP Interface, or another method? I want to take two variables from the actor and update the UI with them.
Longer Explanation:
I have a Third Person BP, an Actor BP, and a UI Widget BP. I also have an interface BP that I was trying to use to communicate between them, I want to update the UI Widget BP with whichever actor the Third Person BP is interacting with. Including things like a “Health” Bar (Which I’m updating in the Actor’s EventTick), and their name.
So Basically I want to avoid casting a bunch of actors to the UI and creating a mess (I’m not even sure how I’d sort it all out if I tried it that way). Right now I have a value that fills up while the player holds down E, or until the actor becomes a “friend”. It’s done in the actor using a Boolean, math and the Event-tick. I wasn’t sure how to do that without using the Event-Tick.
Here’s an example of me trying to store my actor’s updated variables into the Interface to try to later use them. But I really am not sure what I’m doing. Also my game is about befriending animals (the health bar is a friendship meter).
If this isn’t clear enough please let me know! Thank you for any help or suggestions at all.
you can have an interface on the character with some interface functions that return the variable as an output, called something like “GetVariable(variablename)”.
Then the widget only needs to GetPlayerCharacter → GetVariable and then you have access to that variable without having to cast directly to the actor.
If you are wanting to communicate with some actor other than the playercharacter/playerpawn, you might need another way to identify it.
Yo my dude, I’ve come across a related issue recently.
And honestly the easiest solution I have found is to make use of the Omega Game Framework.
It’s an attribute system, which has built in HUD interactions, which will make your information a lot easier to process and display quickly.
There’s a bit of a learning curve, but you are just looking for the basic interaction of the framework, and the UI elements included in it.
Additionally, use of a games event tick, unfettered is expensive.
Making use of Timelines, gates, and loops, which can use the event tick, but will not always be looking to see if they should be doing something.
For UI & Variable updates it’s typically best to create a function that changes the value and have inline logic to call an event in the UI to update it. For replicated variables you’d go with Rep_Notify and have the OnRep_Function call the UI event. Both use a function to change and then call an event.
Both approaches negate having the UI check and update per frame. Pretty decent performance increase.
Health should absolutely be Rep_Notify, and call an event in the widget to update.
Health that increases over time should use a curve (timeline) instead of tick.
More details would go along way to breaking this down into a more exact “how to” & performance optimization considerations.