I am trying to increase one element of a structure with the “Set Structure Members” node but it is not working, or at least it is not working as i intended.!
Am I doing something wrong or the “set member” node works differently ? Any help is appreciated , i want to replace this abomination with the structure if possible :
[Too many variables][6]
*Sorry for bad formating, cant get it to space out as i see it in preview.
edit2: Think i fixed the preview, hope you can help me with the problem.
The issue here will most likely be with how the Player Info is returned from that function. I feel you’re Setting Members of a copy of that struct. Blueprints copy a lot of data.
Could you tell a bit more about how that function works? Especially about how that pin ends up there.
Your logic is absolutely sound. It’s the way blueprints handle structs and copy data all the time; it’s a frustrating experience, especially when one starts nesting structs inside other structs.
In, short: functions will not return structs by reference. They will create a copy of the data. If you then make changes to that data, you’ve made changes to the copy, not the original struct you intended.
When you change the data inside this function, you have, indeed, modified the original player’s data. Outside the function, you modify the data the return pin copied - that data is not the player’s data anymore.
One way to handle what you originally envisioned, is to push the data back in. The function returns the Player Reference (actors, luckily, are always by-ref), so after modifying the copy, set the player’s struct again. Since you’ve exposed only a single struct element, the rest will remain unchanged and behave.