- Home /
Save/Load mutiple game objects as one file
Hello! I want to create an editor based on GameObjects that have both simple (position, size and rotation) and advanced (like sprite image) variables. Not only I want to save/load those integer variables, but also to store the images (and other less complexed things) in this very file. I know that there is serialization but am not sure if I want to use it and how. Obviously I'm not asking to write this all for me, just what should my actions base on to achieve that? Thanks in advance!
Answer by toddisarockstar · Nov 02, 2018 at 01:58 AM
welcome to the wonderful world of byte arrays. everything "stored" or a standard file is in byte array. unity and c# have easy ways to convert floats integers strings and images to and from byte arrays for saving. you can do a quick google for each of the conversions you are looking to use.
when sticking byte arrays together there are two good techniques you can use to be able to split the info back out. you can use headers or spliters or a combination of both.
if you are looking to simply store a couple dozen numbers i would recommend storing your numbers in a string format because its super easy to add seporator characters. if you are not familiar with string functions such as int.tryparce or string.split i woud start your research there. if you have multiple images you need to get back i would reccomend a simple header with numbers saying the index of where the images start in your byte array.
if this is the approach you want to take let me know and i can post code example of where you need help
Thank you for your guidance, I really appreciate your effort. Although, this is not the project I will start right now and I will for sure need to learn many other things, so this is more of a question for the future. But thanks again, am glad to receive some help
Your answer
Follow this Question
Related Questions
Unity Serializer - saves delete after restarting game 2 Answers
Saving Game Problem 1 Answer
Fast, easy serialization library for Unity? 0 Answers
Character Positions Not Serializing or Loading Properly? 1 Answer
Unity Not Loading 0 Answers