Jump to content

save a load game


photo

Recommended Posts

so i started making a "open world"game in unigine and I would like to have a save and load system in my game but idk how to do that
can someone help me?

Link to comment
  • 2 weeks later...

Hi RainWave,

> idk how to do that
You need to serialize all of your major data to a file. Then load and deserialize from it. You can write, for example, these two methods as a base:

// C#

int money;
float hp;
vec3 player_position;
quat player_rotation;

void Save(string file_name)
{
	File f = new File(file_name, "wb");
	if (f.IsOpened)
	{
		// save player's info
		f.WriteFloat(hp);
		f.WriteInt(money);
		f.WriteVec3(player_position);
		f.WriteQuat(player_rotation);

		// save AI positions/states...
		// save environment objects (transformations)...
		// save ...
	}
}

void Load(string file_name)
{
	File f = new File(file_name, "rb");
	if (f.IsOpened)
	{
		// load player's info
		hp = f.ReadFloat();
		money = f.ReadInt();
		player_position = f.ReadVec3();
		player_rotation = f.ReadQuat();

		// load ...
	}
}

Best regards,
Alexander.

Link to comment
×
×
  • Create New...