Saving game every frame?

Im making an rpg like game and i want the cherecter to stay at the same position when the game has closed.
in order to do that, i need to save the position.
and not only the position…
if i will use player prefs, will it slow down the game too much? or its a fast proccess.
and is there another way? because a normal RPG save so many things every frame, like the items which is probably 100 items and every at least a minute you pick up a new item.
so is there a better way doing that or is this the only way and will it makes the game slower much?

The solution is to only save when something saveworthy happens, and do it in a background coroutine where possible.

Store your savedata in a class somewhere and have a function Save

Saver.js
static var savedata : Array; // or whatever

function Save( file, doInBackground : boolean ) {
 Game.ShowSavingIcon();
 for ( element in savedata ) {
  element.Save( file );
  if ( doInBackground ) yield;
 }
 Game.HideSavingIcon();
}

I believe there’s an OnApplicationQuit() function you can use to save all at once, also.

I’d save to a temp file and copy that over to the real save file, to try to prevent corruption as much as possible.

Of course you’ll have to write X.Save, Game.Show/Hide etc yourself, but that’s one way to do it. :slight_smile:

Ok thanks.

One more thing?
is there a way to save alot of variables that are stored in one script, without need to write everything again and again?

I really wouldn’t advise a save every frame.

Online games only appear to do this. It’s because when the client crashes, the server still shows the player as online, and all the relevant data is stored on that server. If the server crashes, I’m sure you wouldn’t think they save every frame. Imagine the bandwidth!

Writing to the hard drive is actually the SECOND slowest thing you can do these days, when it comes to data streaming, so I’d advise against it every frame. A sensible time frame would be when the player leaves a building, or changes maps, or when he brings up the escape menu or something like that.