Does anyone know of a solution for modifying a struct property by reference by name? I’ve a struct containing my players attributes and a passive system in place for earning additional bonuses to those attributes.
The problem is I’ve around 30 passives. The only solution I could find thus far is to have a giant switch statement with 30 options, but it’s really unmanageable and frankly lags the editor in that BP.
Ideally it’d be great to be able to just modify the struct reference variable by the struct variable name. Has anyone figured out how to do this?
My struct defines the attributes, which are then a part of a table. The table contains all the attributes for all the player characters. When the character loads in their struct is pulled from the table and assigned to them. That struct is then modified by reference to adjust their attributes when they get a pickup or passive for example.
The only way I’d be able to use a map in this scenario is I guess convert the struct into a map, but that’s not doable either as some attributes are float, some are int, some are bool, etc..
My entire ability system is already designed with this struct in mind and I’m not about to rewrite a substantial amount of code to change that, lol. I know variables can be accessed by name in C++. If the same works for struct then I’ll look into make a BP node for this.
A map won’t work. You can’t define a table with a map. I don’t want a table with 1 value being row name and 1 value being the map. As explained above not every value in the struct is a float. For example this is my attributes table.
The below for example is just a small part of my attributes struct.
There’s very good reason to be using tables here. They link externally for importing from other tools. Those other tools have no idea what a unreal engine map is. In addition to that I am not going to redesign a large chunk of systems to use a map instead of the struct.
Ok, it absolutely is doable. In C++ you can use reflection to get/set the struct variables by name. I had already purchased the below plugin (which is open source btw on github) so am just going to use it and confirmed it indeed works as I’m needing.