Widget Variable Counter

How to add to number every time another actor of class is destroyed by character’s collision? I.E. starts at 0, when 5 actors are destroyed, number displays int 5

Hello !

I recommend you to setup a blueprint interface that will contain a function like OnItemDestroyedByCharacterCollision, make your HUD inherit from this interface and act on the widget to set the correct value, and call the interface function from where you want.

Or, set this number anywhere else (in your custom game mode for example), and make the widget ‘listen’ the game mode variable using a binding on your counter.

Can I do this inside a blueprintActor class, create a function called Destroy, set up a destroyActor to the function so the actor will be removed from the map. Then I set up on every instance of this, +1, and use a SET and plug that into the level blueprint SET number ?
I just don’t know how I can implement the +1 to variable int into the levelblueprint eventTick section to set the number to number + (variable +1)*#ofinstances

It would have to work like, number + this new variable → SET number
but I’m having trouble adding on destroy new variable + 1 to my function inside blueprintActor class

You can apply what I described previously in your level blueprint too I believe. I cannot check now but I think you can put an interface on your level blueprint.
After that, you override the OnItemDestroyedByCharacterCollision function and set +1 on your variable in the level blueprint.

And for the item destroyed, there is an event called “EndPlay” that is triggered when an actor or a component is destroyed. If it can help you…

I’m having trouble getting Variable into my level blueprint, to add with my preexisting value to display on my widget

If I do something like this inside the blueprintActor class, I still need to get the value into my level blueprint

If you set your variable to stock the counter in your actor that is going to be destroyed, you will lose this value few time after (since the item has been destroyed). You have to set the variable in the level blueprint.

Here is some screenshots of what I recommend you to get the value in the level blueprint.

If you don’t know how to use interfaces, I recommend you to look at the documentation, that will explain more clearly than me.

Got it to work! This was very useful. I will need to use interfaces more, it links the level blueprint and other blueprints easily. Thank you, very helpful.

  • Check if you correctly add the interface to your level blueprint, like in the last screenshot
  • Check if you compile your interface first
  • Recompile your level blueprint
  • Do File > Refresh All Nodes
  • Try again, it should appear