- Home /
Is There A Way To Save A Whole Prefab?
hi everyone, i am creating a game where user will create some blocks ( lets say like minecraft ), next i want is that, when the user exits the game, all the blocks that he has created so far, combine into a single prefab, named " MYBLOCKS " and save that prefab to a harddisk, and when i load the game, the prefab itself loads(it contatins all the blocks, so all of them will also appear at the positions they were before)
is it possible somehow?
Answer by frarees · Nov 05, 2014 at 09:20 AM
Prefabs as you know them on editor do not exist at runtime. What you are looking for is called serialization at runtime. There're several solutions out there. You can try UnitySerializer
cant do serialization, i find it more than just complicated for me
Answer by Redeemer86 · Nov 05, 2014 at 09:23 AM
I think you just need dynamic parenting during runtime and save the transform values to achieve that effect... If I get what you want ...
Red
but how would i load each individuals's name and transform values, can u explain a little more clearly..
Answer by Mathieu_Dossmann · Nov 05, 2014 at 09:36 AM
A "simple" solution is to create a save file containing informations about your objects, whatever they are. The file can be in xml if you want a tree structure, a database or a simple csv file, even a text file if you want. An object contains a position, a rotation, a texture or / a light, and so on, and you'll need to determine what information is need to instantiate them in order to get the same result previously saved.
The way you manage and structure these informations and files is up to you. You could eventually see if on the assets store there is a save file manager that'll match your expectation.
Aside that, i strongly suggest that you look into file management with unity and the script language you are using.
ah yes i know about, System.IO.File.WriteAllToText command, and yes it might help me also, but the problem is, if i use that, than i have to create a single file for a single attribute, and that accounts to 4-5 files per object, is there any way to save all the cordinates and rotation to a single file and read all those data from a single file(for a object), by simple use of this command by the way, it would help me very much...!
Why would you want to save each properties in separate files per object? You can save multiple objects with multiple informations for each in a single file. X$$anonymous$$L for example : X$$anonymous$$L Tree
And so on. In file management (as a whole) it's always a combination of multiple commands to check,locate,write and read informations. Each type of data "file" (xml, sql table, csv, etc) has usually standards about structure and how to retrieve it.
Serialization is nice because you save the whole object and its informations in a file.
any ideas from where i can learn this X$$anonymous$$L serialization?
About X$$anonymous$$L : eXtended $$anonymous$$arkup Language
About C# and Serialization (X$$anonymous$$L included) : Serialization
Why not create a delimited string and read and write it to file
eg:- object_type,location,rotation|object_type,location,rotation ...
After reading this string from file split the string first with "|" then with "," You the all the information about your objects
When you write the data to a file simply construct this string and write to file
Your answer
Follow this Question
Related Questions
How to create prefab from a GameObject variable in class? 0 Answers
What is the best way to load an instance of a gameObject when loading a saved game? 0 Answers
Ingame prefab saving and manipulation 0 Answers
Pressing Apply Breaks Prefab 1 Answer
Dynamically saving and loading player-created prefabs 0 Answers