- Home /
store a gameobject ?
Hi everyone !
I started developping on unity just a few weeks ago so there's probably a way to do it but I can't figure it out 'till now.
My probleme is that I want to store a gameObject from the hierarchy into a MySql database and eventualy load it back later. It's ok for the connection to the database the probleme is how do I store a gameobject in it.
Thank you for answering.
PS : I use C#
What exactly do you need to store within the database?... Is it some information in particular? why do you want to store the entire gameobject?
I want to store a 3d object, like a cube, sphere or an hammer etc...
Thanks for all your answers, if I don't misunderstand a serializer allows me to save/load a class in a .xml file. But what I'm looking for is to store a gameobject in a database, maybe it's more accurate to say I want to store a 3D object in a database.
I want to store/load object file (like .obj, .blend, ...). It would be like the Resources.Load but ins$$anonymous$$d of the resources folder I need to load form my database and store other object in it.
The point is that I want a player of my game to be able to load/store objects from/into a database. Later players would be able to share their database with other players.
Better to store IDs of some kind and have your app deter$$anonymous$$e what it is. After all, each copy of the game should contain all the information it needs to recreate this object with given information so it makes sense to keep the dataflow down.
Serialized to xml can be then stored to the database. You need a blob field or a nvarchar field and then store the xml string in there. When retrieve the data, you can deserialize the string into a class instance again.
Answer by maccabbe · Feb 26, 2015 at 08:29 PM
It seems that you are looking for a serializer. A good, free one that is already programmed is the Unity Serializer (http://whydoidoit.com/unityserializer/).
Answer by spiceboy9994 · Feb 26, 2015 at 08:43 PM
Try this tutorial:
http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer
The thing is that is going to save particular components of your game object. You can decide to serialize any component attached to your game objects. Just keep in mind that the serialization cannot occur on any class that inherit from Monobehavior, so be wise on how to define your components.
Here's a workaround to serialize a MonoBehavior class:
http://answers.unity3d.com/questions/23734/need-to-serialize-a-monobehaviour-class.html
Regards
Your answer
Follow this Question
Related Questions
Ai should delete a build turret 1 Answer
Store level data on server using database 0 Answers
Help on making a Database. 0 Answers