Variable race condition in BP

When using the set timer by event node and getting an input from an event if the event is called twice in a tick then the value can be gotten incorrectly.

This example causes both events to fire but all print strings to output a 1 and never a 0

Silly work around:
72716-

Hi Botanicvelious,

  • Does this occur in a clean, blank project with no additional content or is it limited to one project?
  • What steps can I take to reproduce this on my end?
  • How are you setting the boolean to determine whether or not to set a 0 or 1 value?

Here is a testcase, Download Check out the “Child” BP, when you press “a” and “s” you will see that the value of the print strings doesn’t line up properly.

Unfortunately what I’m seeing seems to be exactly what I would expect. While the Hello 1/2 continues shifting because both timers are being run, the index is updating each time the button is pressed. However, pressing the button seems to change the index as intended. The error you may be seeing is that it is constantly setting the event timer, even though you have it on loop. Try using a doOnce in front of the set event by timer/set array elems to prevent them from constantly being reset. This should help to alleviate some of the error you are seeing. Once the charge is complete you can reset the doOnce to allow you access to the charge timers again.

so even tho i am passing the original “index” the value can still be reset if the function is called again, by design?

Yes, at least as far as I can tell the nodes are working as intended and some tweaking may help to address the specific error you are seeing. Try the DoOnce addition and see if that helps alleviate the error.

The do-once doesn’t help, what happens is the index value is being reset, I assume that is because the function has a variable value for “index” that changes and doesn’t respect the original value of the variable for when the bp started running.

Just a but confusing as you would assume that the value would stay static when its passed into the bp and not be allowed to change.

On my end they don’t change, I’m not certain what is occurring that is causing them to change on your end. It may be beneficial to see if any other blueprints or actors are accessing the same information in your full project that weren’t in the sample you sent me.

I took a couple screenshots that shows why the logic looks like it should work however it doesnt.

What i think is happening is that the “Index” variable is stored in the function and is updated on the most recent keypress so the wire into the “index” value changes

On my end the indexes print 0 and 1 as I would expect based on which value I have selected. I don’t see any indication that it is not seeing the switch as set up within the blueprints. Is there anything else I can do to reproduce this on my end?

It looks like this is by design, however it is a bit confusing as generally you would assume that a value you get from “index” would not change, however as some time has passed it is the case in this situation

if you look at the first image i posed before where I am assuming the incoming value wouldn’t change my assumption is that “index” is for all intents and purposes a constant as it is being passed from a function.

However in this case the function is called again and setting the value of “index” to another value making it so that even tho the index was for example “1” and it caused the correct event to run, on the next run you cant know for sure that the value that has been gotten from index hasn’t changed.

From what i can tell it is this is not a bug persay but a bit of an edge case on how the logic works in bp’s, as generally if you get a value from a function the value you have gotten wouldn’t change later on down the bp

Hi Botanivelious,

Thank you for the update, we will take this into consideration. However, as you said this does seem to be working as intended. I am marking this as accepted for tracking purposes.