Widget component for actor sharing state

I have X amount of backpacks in my level and have a system in place where each backpack is a blueprint actor with a widget component in it, linked to a widget class that’s responsible for a radial progress bar.

The idea is that a player, client or server, approaches a random backpack and starts to pick it up, but the problem is that all the other backpacks in the level also display the same widget component and begin filling up their progress bars for the acting player. They all share this widget blueprint and so all have the same state.

How do I make this progress bar unique for every backpack?

Backpack WB that the widget component in the backpack actor uses:

Yep, a begin overlap event inside the backpack actor blueprint. I’ve tried doing a bool variable to say “IsNear?”, and when this is true, it fired off an event to the Char BP to start the timeline that increases the progress bar value.

Problem is that when I have two or more backpacks sharing the same Widget BP, all the backpacks in the level will be updating their progress bar when I approach any one backpack. I have no idea how to keep them on separate timers while having a widget component in the backpack BP.

How are you handling the fact that a player is approaching the backpack ? Are you using an overlap event ?

Ok so, what is exactly your problem here ? Are all your backpack’s progressbar filling up or do you want the bar to only be seen by the player picking it up ?

I got something working on my end but everybody can see the bag’s bar filling up, is that what you want to avoid ?

Ok, in my project, only the backpack that is being picked up is showing the bar updating, I’ll post an answer with screenshots so you can see if that’s what you want =)

I always makes Widgets as ignorant as possible. I would place the timer on the backpack and have it update the widget as needed. This would also prevent you from having the widget send an event back to the backpack when the timer is done.

I got it somewhat working, enough for you to adapt it to your project I think.
I created the backpack blueprint with just a mesh, a widget component and a box collision to detect any overlap. The widget class I use just contains a progress bar with “is variable” checked.

On overlap, I check if the overlapping actor is a character, if it is, I start a timer firing an event to update the progress bar every 0.1sec (you did that using tick function but I prefer this way so that I’m not calling it when nothing is happening).

Every 0.1sec, I update the progress variable and set the bar percent accordingly, if CurrentProgress/TimeToPickup = 1, we got the backpack, I destroy the actor.

If an actor is leaving the overlap, I check if that’s the actor that was picking it up and if that’s the case, reset any useful variable.

That’s probably not the best system but I guess it’s a start :slight_smile:

Nice to hear =)
I never did something like that before so it was also useful for me, good question :wink:

Good luck for your projects!

Pretty clever solution, got it to work!!

Question though: the set progress percent function, how does that look for you?

I just query the widget of my widget component, cast it to my desired widget class and then set the percent of the bar to what was calculated before CurrentProgress/TimeToPickup.
Be sure to check the “Is Variable” checkbox on your progress bar in the widget blueprint or you will not be able to call it from your blueprint.