I was wondering if someone could show me how to save and load structures placed by the player in game for a base building system. I have a script to place objects but no way to save them that works.
Well, saving and loading is the same no matter what you are doing. One of the simplest is json files. Theres a nice tutorial in the quiz tutorial:
Not really. I’ve gotten the JSON saving/loading down, but as in this thread , it can be a bit tricky to manage.
However, I would recommend JSON over binary serialization, since it’s a lot easier to use and it’s more flexible.
Personally, I use GRFON. I find it much easier to read and edit than JSON.
(Though if are sure you will never need to read or edit these files by hand, then it doesn’t really matter.)
I also had in mind a physics based building system where parts are affected by impacts and can be pushed around. How would I keep track of each object’s postition?
You’d probably have a manager script that keeps a list of all the pushable objects. Then you can simple check the transform.position and transform.rotation of each one when you want to save (or whatever).
Or, have a script that goes onto each of the objects themselves, and knows how to do whatever you need (e.g. saving). A manager script can either keep a list anyway, or use Object.FindObjectsOfType to find them all and tell them to do their thing.