- Home /
Using BinaryWriter/Reader to save levels?
Hi!
I have recently come across BinaryWriter and BinaryReader. What I can tell so far, you can save information with it. If I am wrong, please tell me! But if this is the case, would it be possible to use it to save levels for a level editor? Like saving all the items and objects the player put in the scene. How would I do it? And how would I read it? I have been searching for some information about this for around 30 minutes and I will keep looking for a while.
If you don't want to read the whole text, just answer these questions.
Is is possible to save all the objects in a scene to a custom format? Example: mylevel.gamelvl
How would I save it?
How would I read the information in the file so everything would appear in the game again?
Thanks in advance!
Answer by Cherno · Aug 22, 2014 at 03:10 PM
It's certainly possible and in fact it's relatively easy.
Before continuing: Have a look at Unity Serializer, it is a free all-in-one package that saves and loads everything your want. If you decide to use it, also have a look at this link.
Now, as for custom serialization, the basic code is as presented in this Stackoverflow thread and also this link.. I hope it's ok to just hrow a bunch of links at you, but of course this has been done multiple times, including with Unity, so it's best to see how others have successfully done it :)
Tha way my level save and load features work is that I have everything that needs to be loaded as a prefab, and it has a script that holds a unique ID when the object is created the first time. When saving, the custom savegame class holds an array of all the objects with their corresponding IDs and which prefabs they are. When loading, this inforatmion is used to instantiate the objects again. Things like position, rotation and any custom attributes can of course also be serialized (How to serialize any variables of a class, look at yet another thread! :D
Thank you! $$anonymous$$uch appreciated! I will check all these out and see if I can get something to work!
Also, it is ok to throw links at me. :P
Thanks again!
Your answer
![](https://koobas.hobune.stream/wayback/20220613161240im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
BinaryReader not returning anything 0 Answers
Why does BinaryWriter allocate memory when writing floats? 1 Answer
Problem with my binary files 1 Answer
How to save a ui button for binary formatter 2 Answers
upload file using binarywriter to server 3 Answers