Data type to use to create an undo/redo system that tracks blocks added to a scene

What’s the right data type to use to store an array/hashtable/struct of gameobject cube instances “blocks”? Along with the usual cube properties, the block instances also have their own properties, such as tileType. The purpose of this variable would be to undo/redo…

I’m currently using GameObject, but it may make more sense to just store this as text rather than GameObject’s, and then have the system create the cubes when the redo/undo is hit (etc). For undo’s, I am having the last cube “popped” off the GameObject array.

For redo, I’m having the issue here, where populating a redo array seems to keep the Destroy from removing the block.

I suppose it would make more sense to use a struct or something like that? If so, how would you define it?

If you use C#…

Create a class called Block. Give it it’s properties and inherit from MonoBehaviour.
Create it as a prefab.
In your scene create a generic List
Each time a block is added to your scene, just add it to this list. You could also create your own collection class and inherit from List and use that to manage adding and removing the blocks from your scene.

There are many ways to do it but I’ve found doing it with classes (or structs if you can get away with them) and using generics to manage them is by the far the best way to code these sort of things.