- Home /
Save and Load System of multiple objects in scene?
Hello, I'm trying to figure out the best way to create a save load system to save multiple objects and their positions in the scene.
Not sure if there's a good native way to do this outside the Editor, but for our game, Fossil Hunters, we created a system that gathered up all the objects that matched a specific interface (called ISaveObject) and saved a custom set of data (prefab name for re-instantiation, position, rotation, scale, and 'extra data') as an array of objects in a per-scene JSON file. On scene load, if a JSON file was found matching the scene, we would destroy all the ISaveObjects found in the scene, and instantiate the ones found saved in the JSON file. This required all of our saved objects to be located in a /Resources folder.
Answer by pyramidhead01 · Jul 16, 2019 at 04:04 PM
It's not as simple as you want it to be I'm guessing, it is already covered here, and it appears the submitter of the answer even gives you tips on how to save position and rotation: https://answers.unity.com/questions/803671/i-need-to-save-and-load-gameobjects-how-do-i-do-th.html
If you want a less stressful solution, use an asset in the asset store; there should be free ones available, but the best are Easy Save or Odin Serializer, with either of these two assets you should be able to get help from their community to do that if it doesn't make sense with the tutorials they provide in those assets.
I found a lot of really good save load systems, however I am creating a software that a user will be building something bigger with, using buttons to instantiate the prefab objects. I wanted to know if there was a good way to create a save load system to save those instantiated prefabs.
Yes, if you are plugging in the values correctly, assu$$anonymous$$g the save tool you are using can serialize the data you are looking for then they should all do that.
Here is an example if you want to save the position:
public class ExampleSave : $$anonymous$$onoBehaviour
{
Vector3 positionData;
public void SavePosition()
{
positonData = transform.position;
}
public void LoadPosition()
{
transform.position = positionData;
}
}
I don't know what tool you are using or if it could save a Vector3 (and if it couldn't, I'd be surprised it could save a GameObject), but the two save tools I mentioned can do both.
Answer by GermanHelmet · Sep 10, 2020 at 10:55 AM
this video might help i just sent the last 30 minutes writing a reply then got stuck myself and came across this. ihttps://www.youtube.com/watch?v=4-27sfyj3-w&ab_channel=KennethBurchfiel it solves my prolem hopfully it can solve yours
Your answer
Follow this Question
Related Questions
Fail to load data from json to list of list. 1 Answer
Save and load serialization problem 0 Answers
PlayerPrefs: loading saved data from the menu? 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers