I went to project settings/ input and created an “insert coin” action mapping on the controller left special (select) and the keyboard 5 key.
I created a credits widget and placed a horizontal bar in the lower left hand corner. I added the text “Credits” to the left and added the text “0” to the right. I selected the 0 text and chose to bind to the text. It was at this point I discovered that you can’t get variables from the level BP.
Added to viewport in the level BP.
So supposedly an option is to make a variable in third person character bp that you will get access to in the widget using cast. I made an integer variable called “Coin Counter”.
The widget does display but pressing select does not change the zero on screen. I noticed that when I played the game the widget had updated from zero to 1 but it was not progressing further.
I would suggest using an Event Dispatcher to broadcast whenever you change the Coin Counter Variable, so that the widget can bind to that and update the Text. This would be more efficient than using widget binding.
Create an Event Dispatcher in ThirdPersonCharacter called something like OnCoinCounterUpdated
Select the newly created Event Dispatcher and add an Input to it called CoinCounter and set the type to Integer.
Ok thanks for the help. I created an event dispatcher in the third person character but I’m not getting the option to name it nor can I change the variable type to integer. Are you using UE5? I’m using 4.
I’m using UE5, but it should be the same on UE4.
You need to press the + button on the top right, just above the “Copy Signature from” button. Is that button missing?
Ok found it and have done most of what you said. Just need to connect text counter in the last pic. That is an obj reference, from what exactly? The counter is an integer?
We can then use that variable to do whatever with the text block. like setting the Text.
The reason I suggest not using the binding is because, that function will get called every frame, but since you’re only updating the Coin Counter variable when clicking a button, we only need to update the widget once, when Coin Counter changes.
This is where Event Dispatchers help. This is more efficient since we’re only updating the widget when the variable updates.