First I want to point out that the print string should only be used for debugging purposes or showing the *dev *various values while in the editor. In a packaged game, it does not even show up. So if you want to show text to the user, it should be through widget, or some kind of 3D visualization.
So, here’s some pictures with explanations. Read it all first without actually doing the things, then decide what you want.
Explanation:
- We create a string variable inside the widget.
- This allows us to bind the text of the text block widget to the string.
- We create an event (or if you prefer a function, do that), and add an Integer input to it. When this event is called, it’s going to take whatever int value is passed, convert it to string and set the Coin Text Variable to that string.
So, how do we call this Update Coin Value Event?
Well, the way you have it set up right now, is that when you overlap with CreditPick actor, that creates the widget. I would not do it that way and will show how I would do it, however I will at the end include an example of how you could keep your current way of doing things.
How I would do it:
Explanation:
Inside the FirstPersonCharacter, after the begin play event, we create the widget that shows the coins text. We should store it as a reference and we do that by creating a variable of that widget type. That can be easily done by right clicking on the return value and clicking ‘promote to variable’.
Now, it seems like you only want to show the coins text when you pick up a coin and after a short period hide it? If that is the case, the following graph works well. However, if you always want to show the coin text, just add the “add to viewport” after the begin play event and remove the “remove from parent” & “delay” nodes.
Explanation:
When the overlap happens, you cast to the player character and call the event/function. In this example it is an event. Note that the Delay node can not be used inside a function.
- We get the total Coins variable and set it to a new value which is the current value + a random 0-19 value.
- We add the coin widget to viewport and call the update coin value event, passing in the total coins value.
- we begin a delay function, which when completed, removes the coin widget from viewport. Note that it is not destroyed.
If you go with this, things to delete from your current setup: The binding in the widget, Everything after & including the “create droidremain widget” nodes.
So, what if you want to keep your current setup.
In the First person character, ignore the creation of the widget after the begin play event. With the “addCoin” event or function, only include the setting of the TotalCoins variable, ignore everything else.
In the widget graph, instead of having an event with an int input, we just have an event with no input.
Instead, when the event happens, we get player character 0, cast to FirstPersonCharacter in your case, get the total coins value, set the text variable with that value.
If you go with this, things you need to change:
In the CreditsPick actor, before the delay node, call the Update Coin Value event in the widget.