Can't edit a Bool within a Struct Array

I’m using Structs to hold editable data for different control schemes in my game. As part of this each Struct also contains a ‘Current Controller State’ bool so I can tell which of the States is active.

I use a ‘ForEachLoop’ to go through the list of available controller states and set the bool to be true or false on each state every time the player changers controller mode.

However, the bool change never seems to save / register. If I check the Bool of the current Array Element Struct immediately after it’s set to be true, the game will still report the bool as being false. See attached pic.

Hey Jimmy_Jazz-

Could you post a screenshot that includes more of the blueprint so that I can see where the boolean that is checking the branch is coming from? You should be able to use a “Break” node after you set the members. From the break node you can set the Current Control State to a boolean variable that can then be used to test the branch node to check if it was set properly.


Here you go. I’ve added a break with a Print String before it to confirm the order.

The logic sets the bool in the Struct, then prints a string to confirm it has been set, then breaks the Struct and branches based on whether the bool is true or false. At which point it is always false.!

Hey Jimmy_Jazz-

I tested again and found that there is an issue with using the Array Element output of the ForEachLoop node that is causing it to not be set properly and submitted this bug for investigation (UE-8884). For the time being if you drag off of the Array Element pin of the loop node and promote this to a variable, you can use that variable as the struct reference for your break/set struct nodes and you should be able to set it properly.


Your temporary solution seems to works initially, but a subsequent loop that totals up the amount of ‘Current Controller State’ set (used to make sure that it’s neither 0 or more than 1) fails to the Bool as true in the struct that it was previously set in.

In the image below the ‘True’ output of the branch node never fires, despite it being confirmed by the Blueprints above (with your solution) that the ‘True’ bool was set once. Both sets of ‘ForEachLoop’ nodes point to the same array variable.

What’s happening is that the variable is being set to match what is in the array, the array itself is not actually changing. So when you pass in the array to the second loop and reset the variable it is being set back to the default values inside the array. The simplest solution would be to use a “Set Array Elem” node after the “Set Members in…” node. You can pass in the array you’re using as the target array and the current index of the loop as the Index. The “Item” would be the variable that is used to set the struct members (Controller State Array Element in the case of the screenshot).

Also, be careful of having a For Loop triggering another loop in its loop body. Each time the first loop runs (each element) the second loop will run through completely. This means that if you’re passing in the same array to each loop the second loop will be accessing elements of the array that have not been set by the first loop yet.

The bug entered was in reference to the array element output of the loop node not saving changes and was marked as by design. This is because with the node you’re operating on a copy of the struct instead of the actual struct.

Thanks, I’ll give that method a shot.

The second ‘For Loop’ runs from the ‘Completed’ output on the first ‘For Loop’ so hopefully with the adjustment above everything should work fine.

Is there any way I can keep a track the status of bug (UE-8884)?

Phew, that worked, there was definitely some confusion on how to changes part of a Struct within an array.