I'm making a kind of infinite runner style engine. It generates the terrain in chunks each time a milestone is reached, and stores each chunk as a custom class in a list.
To minimize overhead, it only instantiates required chunks as game objects, but keeps the data to re-instantiate one.
Obviously the list will keep getting larger the longer the player is able to survive. However I want the ability to go backwards, so I don't want to destroy the chunks, but I also don't want keep potentially hundreds of them in ram.
I could regenerate them when going backwards but that will involve rejigging the whole seed system.
Is there a succinct way to serialize unused elements in the list to disk when no longer needed?