Download

Storing a lot of Pre-Defined Struct Data

Hi there,

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.

Do you mean fragile during runtime, save files, or what? I have never had any struct data compromised, but perhaps I haven’t put them to full use.

You might look into data tables for blueprint. C++ probably has options, though that isn’t my area of expertise.

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.

Try storing the data in a JSON or similar file, and set your InitializeData function to load the data from JSON to the struct. You’ll need to write some C++ code, but it should make it a bit easier.

Yeah, I also initialize all my settings somewhere in the beginning of the process. I haven’t had any problems with it in all the months that I have been using it.

At some point I plan on having all of my data in a data file for storage and user modding though.

Hi Axtel,

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?

Cheers

Hi, when you say a data file do you have any specifics in mind?

They were also having problems with blueprint structs in the data tables until 4.6. Should be good to go.

I don’t know if other issues that you might have seen with BP structs were also fixed with 4.6, but that would be a nice bonus. :slight_smile:

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.

That’s amazing, thanks. Will give it a shot tomorrow!

Cheers, I’ll post back when I inevitably get stuck :wink:

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).

Do you spawn that actor in, or is there an alternative way? I’m working on a multiplayer game and all this info needs to be accessible by all players regardless of area/instance.

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:frowning: 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.

https://arcadekomodo.com/home/wp-content/uploads/2014/10/Screenshot-2014-10-30-04.10.41.png

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.