- Home /
how to serialize unity variables? (Sprite, Image ...)
Hello
currently i am doing C# serialization to save and load player data.
and i am following this tutorial http://gamedevelopment.tutsplus.com/tutorials/how-to-save-and-load-your-players-progress-in-unity--cms-20934
but how can i serialize Sprite?
edit#1: anyone know can i serialize a whole class? if i have a class full of variables how can i save all of them together instead of one by one
Why would you serialize a Sprite ?
Can't you serialize its path in the resources folder and instantiate the sprite from it when you load your game ?
You could store the texture as a byte array which is already a first step.
I support Hellium's suggestion. Just store the prefab name and/or path as a string, and use it to instantiate the prefab after deserializing. The only time I would consider storing the actual sprite texture is if it was generated at runtime.
but what about other variables? GameObject, Transform ....
Take a look here, where I explain how to serialize GameObjects, and other Unity-specific types like Transform and Vector3, with a sample project.
Answer by Voxel-Busters · Aug 07, 2015 at 12:06 PM
Bump! Recently we released a serialization plugin which exactly does what you are looking for. Meet Runtime Serialization for Unity, fast and efficient tool to serialize c# objects as well as Unity objects like GameObject, MonoBehaviours. For compete list of support types, please check this link.