Saving multiple instantiated Gameobject

Hi !

In my game, the player can build a farm and house who are basicly just some gameobject than he instantiate on the scene.

My problem is : how to save this gameobject ?

Also, if he instantiate some carrots for example, i need to save the “GrowLevel” of this particulor instance of carrots plants.

Any ideas ?

Hey, I can give you some hints if you want, about serialization, and how to save some data to disk. From what I understand, the player should be able to save if he have built a farm and/or a house. For that, why not just an id for both of them? Then, for the farm, there’s another problem, the growth level. You’ll also need to save the positions of the objects.

What I would do there, is an array of byte for saving this. The first byte, the ID, will indicate how many bytes this building need for his data. For a house, you’ll only need the position. For this, you’ll just put the bytes of the positions right after : eg :

(this is a quick scheme)

id —X— —Y— —Z—
(0)(0)(15)(0)(12)(0)(3)…

that would be if the X, Y, Z positions were made of 2 bytes, so the type short

Still following?

That mean, each building will need 1 byte for the id + sizeof(position) bytes for the pos + x bytes of data.

For the farm, it get a bit harder. Let’s say the farm ID is 1. When, when you read, you see a 1 as id, that mean you’ll need the position, the plant type(1 byte) and the growth level(1 byte)

That give us an amount of bytes of : 1 + sizeof(position) + 1 + 1

This is not so hard, when you manage to understand it… :slight_smile:

If you need help to create the script, I’ll be happy to help you :slight_smile:

good luck forward, FireCube