So, I’m trying to get saving and loading going, and for things such as basic player statistics like health and all that, well it’s a breeze really. However, I’m having issues with things that aren’t the player, at the moment I’m just trying to get pickup items saving and loading, but I’ve figured that game objects can’t be serialized without using a plug-in that someone else has made, however I don’t really want to do this, because I find other peoples stuff difficult to work with. I did actually try to completely reconstruct the game objects by passing the basic information around, information such as its position, but then there’s the mesh collider and textures and all that which also need to be added onto the game object before it gets instantiated, sooo I though it might not be the most efficient way. Is there something that I’m just completely missing, or is that kind of how I’m gonna have to do it?
Use UnitySerializer. I wanted to script everything myself and I did a fairly good job for a start, but UnitySerializer makes everything so easy…
For your example: meshcollider and textures should be in your prefab and not in your savegame, if they are the same every time.
I did try UnitySerializer, but I just couldn’t get it to work, I went through the guide, watched a video of the guy using it, but all that was from a good 2 years ago, so the interface was almost completely different, that’s what I mean by I find other people’s stuff difficult to work with.
The textures would change depending on which item is getting picked up, although I could just make a reference to which texture is needed then go from there, it’s just that it seems really, bad, like Unity just completely neglected the fact that it’s a GAME ENGINE, and game’s save.
EDIT: I should say that I did get UnitySerializer to work, but very poorly, the objects could get saved and loaded, but their textures wouldn’t load, and just in general weird things were happening.
I’m not sure what you think Unity has neglected here. There are a variety of ways to save data, depending on your needs. The texture changing issue is just how you have things set up, you’ll need to reference the texture if you are changing it.
But really, you shouldn’t be storing game/display data as part of player save in the first place. The proper approach is to save a reference to the whatever the object is and information about its state (location, game values). Saving all the gameobject data is unnecessary data. More importantly it creates a dependency where one isn’t needed. If you need to update the game or make any changes, you will either break it for the player, or have the game do things you don’t want. (or keep track of everything you have ever possibly created and maintain it). Also if you are storing player save data locally, you are asking for all kinds of problems.
For example, if you want to store a healthpack, where ever you are storing your data you would only need to save:
HealthPack (or usually a unique id), location, value. (or any other data relevant to the game. )
The game would know how to reconstruct it. The save doesn’t need to know what mesh or texture or collider it uses/needs. You should only save the information that is actually needed and specific to the game.
Yeah I made a prefab then just instantiated it and set the position and item ID, I probably should’ve updated this a few hours ago when I did that xD all I have to do now is sort of, clear the area cause at the moment when I click load, there’s items flying everywhere, literally, because of collisions, but that should be easy enough, I’ll just remove everything from the scene (at the moment I just have placeholders everywhere) then clear everything when the load method is called. Thanks though for the replies.