I’ve been running into problems where using set members in struct function would overwrite any empty pins with default values. After about 2 weeks of beating my head against desk, I worked it out a few minutes ago.
Solution: When editing custom structs in BP using Set Member in Struct function, select node, and under node properties hide any pins that you are not updating. This will make it so that it does not update anything but what you actually have connected.
Testing:
Create a struct with default values.
Pass struct to a function
Inside function do something to edit variables and then try to assign something to each of them them with “Set Members in Struct” without hiding any pins.
Next, make some more edits, and then try to assign values using Set Members in Struct. Leave some pins empty but not hidden.
Print Struct.
Next, alter second struct by hiding unused pins.
Print struct.
This method works on structs of structs, and structs of structs of structs.
To be tested:
I have not yet tested if this will work with structs within an array. it would be worth testing though.
This has been tested in 4.6.0 and confirmed to work with Arrays of structs. Just remember to set your array element after setting members of your struct.
If you make a change to struct itself, reset element in array with struct. i.e. edit struct then do an array set element and pass it newly edited struct.
if you will post up a picture of your current setup I will have a look and help if I can.
Beter solution here. We have a backpack with an array of InventoryItem structs,
I pass in struct by reference, then break it, then set all fields, then set to a local struct (forcing a copy)
then return by value. You then put this back into array.
I’m doing an inventory system with dropping items out of inventory, spawning that actor in world but need to pass struct details from dropped item to spawned item in world. . . . problem being is construction script of spawned item is setting default values for class object.
Screen picture is below of how i’m trying to implement this… i have CONFIRMED through several rounds of PRINT STRINGS that variables are INDEED getting passed through custom event bind (coming from my HUD ON DROP action, calling event dispatcher in my controller script) so variable passing is not an issue… it is SETTING these variables upon spawn of actor class. Any solutions out there for this? This post and one other are only relevant posts i see regarding this information.
This is also why I was mentioning delegate binding in construction scripts in one of my other posts. We ran into a similar problem and I am not yet certain how to work around it.
Heh, how can i convert struct to a class and create some objects using that class? I can’t see any possibility to do this using blueprints, i afraid i have to start my project using raw c++ code to achieve any good result.