Easier way to multiply structures?

My game has attachments that modify the gun’s stats and I need to multiply every value in one structure by the same section in the next structure. Is there a cleaner more efficient way to do this?

If this were a c++ struct you’d overload the * operator there. In BP… no.:

operator overloading - cppreference.com

Because structs can contain so many types of data which can’t be multiplied such as pointers or text in any meaningful way, there’s not a one default or automated way to do it. You could consider not placing these values in a struct but on a map on a class, then iterate over the values in the map.

UWeaponModClass:
TMap<FGUID, float> IDToValueMap;

Structs are useful to carry data from A to B but when things get more complex or when you want to add logic to one you are better off implementing just a “class” which in the blueprint environment would be a UObject. A bit more bloated, but useful in its own way.

Something else, you are using a “Set members… node” which takes a reference but your input and output is a copy. Intentional? A dot shaped pin is a copy, a diamond shaped pin a reference.

1 Like