problem setting array element value

Hi everyone.

I started having this issue lately. I have made a struct for doors in my game which has some elements. A variable in the first person character uses this struct type as an array.

Now, in an actor class called Door_Button_BP, a cast to first person character is done and one element is modified in this array variable which resides in the first person character. The element value is changed inside the Door_Button_BP successfully (a print string is used which prints the modified value). After the element value is changed, a cast to Door_BP is made to activate a custom event. The custom event also casts to the first person character to get this same array variable and print the modified value of that element which was modified earlier. A print string is used to print the value of that modified element but it just reverts to the default value. Very strange.

Even more strange, another similar array variable also in the first person character with another struct is able to change the value of its elements in the same manner and inside the same Button and Door blueprints.

I tried something which worked so far, I made the array variable inside the Game Mode instead of the first person character and it worked with no issues.

Any help on this issue please??

It’s difficult to speculate, Are there structs inside the struct? Array inside the struct?
Would need the project or screenshots.

Thanks for your concern. I was able to figure out the problem!!

The problem is that I made a reference variable of the original array variable and was saving to the reference variable. I added a set node to save the contents of the reference variable over the original variable and it succeeded!

Setting a new value of an element inside a local reference variable seems to make the change only in the local reference inside the blueprint class which has it, and does not make the change in the original variable which resides in the first person character. You should set the new variable first in the local reference and then set that over the original. Or, you can simply use casting always and don’t use a local reference variable of the original variable. Or, it can be done making a reference to the first person character and not a reference to the original variable itself instead of using a lot of casting nodes which is how I did my project.