If I have a struct that stores information about a character’s abilities, such as the speed, damage, effect type, name, and so forth it starts becoming a problem when there’s a lot of abilities because of how fragile this data is contained.
What is a better way to make sure the data doesn’t vanish? If I change the damage variable name all those values are lost.
I could do it in code, but want to know what options are there.
I mean there is a LOT of information entered about player abilities and weapons, but if I so much as rename a struct variable it resets the information. Doesn’t feel like it’s safe and I keep having to repeat it.
At the moment I’ve built a macro library and function library. I have a macro that the function ‘InitializeData’ uses to enter the relevant information. Seems to be doing what I need so far, and then I call the functions (where the info is stored) on BeginPlay event to set the struct data.
Might work just having this function / macro library for setting all game-wide variables / data.
Thanks for the suggestion. I have no prior experience with JSON but definitely need to get some. I don’t mind writing C++ code. Two things - If I load said data from the file, is there any way that in the shipped product a user could open it up and modify it? Or, how safe is it from external tampering?
Or, did you mean to have JSON load the data into the engine itself simply to keep it safe?
Hi, when you say a data file do you have any specifics in mind?
I make excessive use of data tables; you can literally whip them together in Notepad. I use them for all SORTS of stuff for my character’s attacks.
Be aware that accessing this data isn’t as easy as accessing a Struct though; you need to use individual pins to break out the data table content by row, usually, and may then have to re-apply those values into pins of the structs you’ve defined for your project so far.
But once you make the initial investment of effort I would argue it’s well worth it for the organization of data. Data tables are pretty much designed for specifically what you’re describing, which is acting as “permanent struct arrays” which associate recognizable names or row numbers with a whole mess o’ data.
If you’re making a structure that itself contains a lot of structure variables, i find that it becomes prone to instability. What i personally do is store all of my skill structures in an empty actor blueprint (which won’t be permanently empty, but never has to have anything in it other than variables).
TheData Table/User Defined Structure combo works well as of 4.6. However, there are lingering issues with updating members in an array of structs Ticket JIRA UE-6451 has been submitted to correct. In the interim, I elected to use a Structure of Arrays as a workaround. A Structure of Arrays is two or more Arrays of an individual Data-type encapsulated into Virtual Structure achieved with some fancy Labeling and Categories/Subcategories (ie: VStructure|Array|Structname). I use macros to perform array operations (Add/Insert/Remove) on all arrays in the VStruct to maintain index alignment.
The more arrays the more expensive. The trade off update/modify Member with greater granularity flawlessly. You can get even more fancy mimicking a link list, but, ultimately I’d rather be able to update a Struct Members in Array of Structs.
AFAIK, if you tell the engine to pak it along with the rest of your content, the end user should not be able to get to it. Although, if you really need to, you could store it as a compressed file, and then load it to a FString. That would probably be the safest way, as the JSON reader only needs an FString with the JSON file contents in it.
And yes, I meant have your code load the JSON data at runtime. JSON is strictly a data storage format.