Displaying Integer/Objectives on UI? - Alternative to "Get Actor of Class?"

Hello all!

This is the situation.

I have a simple objective in my level. The player must pick up garbage and throw it into a trash bin.

The class with a trigger box in the trashbin (aptly named TrashObjective), has a counter that bumps up an integer variable. I need the number of items in the trash to display on the UI.

I set up a binding for the text box and was having a very hard time getting it to work. The problem was the “object” field of the “Cast to Trashobjective” Action. I found a solution of placing a “Get Actor of Class” and selecting the Trash Objective class.

This has the integer value showing as it should, however, people online said that this was a bad way to go about it.

Below is an example of my current blueprint for the UI. I want to know the most proper way to go about programming this so I can repeat it for other objectives.

thanks!

Not only would I agree but also risk stating that binding is rubbish to boot. :innocent: Consider the following instead:

  • widget with a text block and a custom event:

image

  • since the Trash Objective does the counting, create the widget there:

  • bin gets hit and updates its widget

That’s it, no Get All, no casting and the whole thing updates once per rubbish hit rather than 120 times every second (that’s how binding works). An Event Driven - example 3 approach like this will also be easier to debug when things go wrong as they always do at some point.


There’s, ofc, more to it. You may want to have 10 Trash Objectives and only a single counter for them all. Do tell if the above is enough for now at least.


And it’s not only the Blueprint Police Force that is upset with this, the editor itself says it’s a no-no:

image

Get (All) Actor + Binding that does fire every frame is a horrible combo, indeed.

Thank you for the reply! I am getting a better understanding of more optimized blueprint-to-blueprint communication.

I do have a question though… I do not see the ability to add “Update Text” to the objective blueprint.

It’s a Custom Event you add yourself:

You can then give it a more relevant name and have other blueprints call it which, in turn, executes any connected nodes that follow. Also, not all widgets are exposed as variables. Text Block is not, in order to update its fields directly:

image

You are a wizard!
Thanks for all the help!

I feel like I am almost there

Here is my Widget in my UI folder for counting

And here is my objective blueprint (the tag on the top portion is for making sure the object that counts has the “trash” tag so throwing other objects in doesn’t add to the counter.

Sorry if I am repeating myself but I just need help marrying these two blueprints. You’ve been very helpful so far and I think I am pretty close.

And connect the wires as in the earlier pic. It can be done without assigning the Return Value to a variable but it is good practice.


And it seems you do not need the Trash Box variable.

Excellent. I did not know about custom events. It is all compiling but the integers are not appearing on the widget (communication breakdown between blueprints?) On paper, they look just like your screens, but in practice, they are not working as intended.

PS. For the time being I kept my own script with “Get Actors” running for debugging, is that causing a conflict?

Again, thank you for your time.

1 Like

Could you show the screenshot of the TrashObjective with everything connected? Also, if you’re using the same widget as before (the one with binding), ensure there’s is no binding:

image

As it would override any values set to the text block.

That was the ticket!

Thank you so much for your help!

1 Like

This video covers the basics of blueprint communications.

I highly recommend spending a good amount of thought on what class/object/instance are.