Download

Blueprint "Set members in struct" on a nested struct

I am using a Data Table to initialize the values of a custom struct with the purpose of creating a character customization screen.

Can anyone help me understand why my variable isn’t being updated when using Set members of S_Styles? I am using a nested struct of this nature:

Mesh Data {
Animation Blueprint : Anim Instance
Slots: HashMap<String, S_Slots> {
“Hair”: {
Styles : Array<S_Styles> [
SkeletalMesh : SkeletalMesh
Materials : Array
MaterialIndex: Integer
],
CurrentIndex: Integer
},
“Torso”:{

}
}
}

CurrentIndex indicates the last selected S_Styles in the Styles array. When I try and use set members in S_Styles on a given key in the hashmap, the Struct Out Current Index indicates that the value has been changed, but when I repeat the FIND function on the same key, it shows the value has not been changed. Any ideas?

Hey,

Map::Find returns a copy, and you’re changing that copy, not the struct that’s inside the map. After setting the members, you can do an Add on the map with the Key and StructOut (so overriding the stored value with your new copy).

Ok! So that seems to work. Quick follow up:

I’m sure you just know from experience, but how does one find out that Map::Find returns a copy? Additionally, is overwriting the struct the only way to update a member within a struct? Feels like a lot of effort to just increment an int.

I’m sure you just know from experience, but how does one find out that Map::Find returns a copy?

I’m not sure if the description says or not, I just know from experience. You can also check out the source but I’d suppose that such a low-level function is not exactly super legible.

Additionally, is overwriting the struct the only way to update a member within a struct? Feels like a lot of effort to just increment an int.

Updating a member in a struct is as simple as that one node (Set members). The problem here is the map; and yes, in blueprints, there’s no simpler way to update a map value than re-adding the same key with the new value. Of course, in C++ you can find the pointer to a value for a specified key, so it’s only a BP limitation.

Great, thank you for the information. In the end, I’ll be moving the majority of the work to C++ but have been prototyping in blueprints. This had me halted for much longer than I had wanted so thank you for your help @KristofMorva!

1 Like