Saving a grouping of objects in a scene

Hey all,

Trying to figure out an issue I am going to run into. From what I understand you cannot Serialize a List into a save file so I am trying to figure out a way to keep track of random events that is currently going on in a scene.

Quick background info. I am doing a Space Sim type project. I have an idea that I will have a random list of events that can go on in a Scene (a single system). Each event would be something along the lines of pirates attacking sector A, alliance defending sector B, etc etc.

So for an example of my question. Lets say I have 20 different events (each event has its own data set) within a single System (scene) and they can happen randomly over the course of an hour. I have a SystemController that does the main data of everything happening in the scene but I am not sure how to capture which of those 20 events are currently ongoing, so if a player uses a jump gate to go to the next system (scene 2) and then comes right back to the first system then the same events are occurring.

I can figure out how to do this by adding these Event objects into a List but if I cant save that into a save file I am not sure how to hold onto that data.

Would appreciate if someone can give me any ideas on how to tackle this. Thanks!

Rather than save every piece of information, what you’ll want to do is work out “What is the minimum amount of information i’d need in order to recreate everything like this?”

Lets tackle this in another manner. Imagine you are playing chess with a friend but you need to pack up and when you get home, you want to continue this game using your chess board at home. How would you solve this with only a pen and paper? You might draw the board and use an icon to denote each piece and colour. Once home you could simply recreate the board state and off you go.

Saving and Loading can be solved in a similar manner. Build a set of arrays and variables that represent how the “board” looks and save those to file. These variables only need to contain the minimum information required to set it all back up again. When you load up, read these arrays and variables and recreate the scene.

Good explanation but it goes back to the root of the question of how to save an Array or List of these game pieces when you cant use an Array or List in a save file.

Lets break it down a bit;
Scene 1 has 20 items, 5 of which are active at any given time.
Scene 2 has a different set of 20 items, 5 of which are active at any given time.

Normally I would have two lists, one list to store the 20 items in the scene, another list to hold the 5 currently active items which is what I need to save. Technically the long way around is to make a single bool reference to each item within the scene save file to check if they are active or not upon load, but if in the end one scene has 20 of these items and another scene has 35 of these items it may become a null reference mess.

Of course I may be just thinking of it in the wrong way

I believe I may have been mistaken and that you actually can Serialize and save an Array as long as its not a custom class. So if I give each of my active items an unique ID number I can put them into an Int Array and can call on that when I load the save file. Feel free to correct me if I am wrong.

1 Like

Yes you have it correct.