I’ve been banging my head for the last couple hours now and can’t seem to find anything.
It’s simple… Or at least it should be. I want to be able to communicate via interfaces to my HUD widgets, but I don’t want to have to make a “get” call from the HUDBase every time and set a local variable in every blueprint (Event BeginPlay) that can communicate with a widget. Instead, I want one public-public object reference variable, that is declared once in the HUDBase (or wherever), and then other blueprints can access.
If that’s not possible, feel free to throw your most efficient ways of handling communication to the same widget from multiple other blueprints. Or online resources you think will come in handy. For context, I’m trying to script my weapon widget, that shows ammo, fire mode and a text if the player is out of ammo or has no weapons and tries to switch weapons. Since there will be multiple weapons - and multiple characters - there will be a lot of to-and-fro interface calls.
I can post my current blueprints for my dummy weapon, character and widget if you want to take a look.
You can have global variables which are actually assets using a system like this:
You could make your own version of this using the game instance. Instead of keeping variables in the widgets, why not use them from the game instance?
So you need a kind of global widget reference? When the widget gets created, it can put a reference to itself in the game instance.
The system you linked is nice and I could see myself implementing it somewhere down the road. Right now, however, accessing variables isn’t a problem. I’m using a Blueprint Interface to communicate between blueprints - say, the player fires their gun - this messages the gun itself and triggers the “Fire” interface event. With this I have no issues, because, in a way, the weapon and the character owning it are paired together. But there’s only one widget and it needs to be messaged by multiple blueprints, which can change in the course of a game, but the widget stays the same.
So, basically, I need to be able to reference the widget a multitude of times from mutiple places.
Yes, exactly, a global reference. Guess I’ll have to read up on the Game Instance blueprint and what it’s used for, because right now I haven’t the faintest idea what it is. May not outright fix my problem, but it sounds like it can help.
Game instance is very like Game Mode, Player Controller etc etc.
It’s one of these blueprints that’s constantly available in the background.
But with the GI, you get one when the game starts running, and that one exists for the duration of the game. Exactly what you need if you ask me.
Added bonus, sort of, if you talk to it with blueprint interfaces ( rather than directly access the innards ) you can use it at any time without having to cast…