And what I’m doing is, if player collects coin, I add 1 to the coin collected variable inside player’s BP, I match it with a local variable in HUD and if either is not equal, I set visibility of “COIN COLLECTED” and also set the value of the local variable to the value of the player’s variable so that they become equal again after which, after some kind of delay, I set visibility to false. Problem is, variable value is acting very weird.
My PrintString’s duration is 0 so it should update immediately…?
But for some reason, the value is being printed multiple times as if I have multiple PrintStrings running
Basically, this keeps showing me the local variable to keep resetting itself to 0 on every tick somehow
That’s the whole point of using local variables. A function terminates, variable goes out of scope, next time the function executes, the variable is at defaults. Also, you cannot have a latent action (delay) in a function.
the value is being printed multiple times as if I have multiple PrintStrings running
Once you bind a function to a widget field, that’s precisely what will be happening from now on. Those functions do run every frame.
we create a widget, store a reference, add it to the viewport and hide it
when the player runs into something:
– ensure it’s a coin and destroy it
– count it and send the value to the widget, show the counter
– if no additional coins are collected within X seconds, hide the counter
This way you do not need to run a function every frame, which is considered wasteful, and you do not need to duplicate variables.