Math inside functions?

I was trying to make a function in place of a mess of floats, my goal was to make a “hold button timer”, basically just adding .1 to a number every .1 seconds, once it reaches 1, trigger the action. However I noticed functions seem to just run with the default values, as in Set Variable 1 as Variable 1 + Variable 2 will always result in the same number within a function, even though outside of the function that would make it gradually rise. It works just fine outside of a function, I just wanted a cleaner version of it in my BP.

Is there anything I can do to get around this? I wanted a function where I could just input different values if necessary to make holding the input down shorter or longer.

you could use a macro, or have the variables outside the function, just drag the pins the the input or output node and it will link it to outside the function

You will need to pass a variable into the function that will then and modify it, Then return the value for the caller to set the variable to that value.
An alternative would be to pass the variable by reference.


Make sure that the variable scope is outside of the function and you are passing it by reference.

Have a look here:…-a-functi.html

Sounds like a Timer is what you need. Just set the timer on Button pressed and cancel the timer on early release.

Thanks for all the options, I’ll check them out ASAP.