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.
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:
Get (All) Actor + Binding that does fire every frame is a horrible combo, indeed.
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:
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.
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?
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:
As it would override any values set to the text block.