Download

Do Once not Doing Once?

So I’ve been looking for a solution to a situation for a few hours now and Do Once sounds like what I need. I basically am looking to see if something is above or below 50 and if so, add 1 or subtract 1 from another value (this is used for damage calculations in my setup). I figured Do Once would work fine for that, except that its doing all the time! It doesn’t fire once and then stop. If I check the “start closed” option, that works, but that obviously doesn’t help me.

Has anyone else experienced this?

Hmm I think I might have had an issue with that node, but im pretty sure it was my own fault. Can you share a screenshot of your blueprint?

So I did some testing, and it looks like if DoOnce is inside a Function, it will not do once it will do each time the function is called. Is this something related to the nature of how functions work that I’m not aware of?

When the function is called, the code inside is executed as it stands. “DoOnce” means when the execution pin hits it, it runs once and then stops. Assuming blueprint functions are the same as standard functions, anything inside can be considered to be local to the scope of that function. This means that they are created when the function is called and pushed onto the stack and destroyed when pushed off.

Your solution for this would be to have a branch before the DoOnce to store a blueprint wide “static” variable boolean that can record whether or not it needs to be run again.

2 Likes

Maybe 7 years late… however, if anyone is looking for a simple fix:

You can also run a branch node at the start en promote the condition to a variable. After your branch node (false) set the promoted variable to true. It’s a small setup but works like a charm! If you want to reset the function, just set the promoted variable back to false.

1 Like