Search Unity

De-serializing GameObjects Without Instantiating

Discussion in '2D' started by twoski, Jul 20, 2014.

  1. twoski

    twoski

    Joined:
    Mar 27, 2014
    Posts:
    27
    So let's say i have a GameObject, which is essentially a container for several other GameObjects.

    When i destroy this GameObject, i want to save all of its stored data to a file, and I want to be able to load all of this stored data at any point and assign all of the saved data to an existing GameObject without instantiating an entirely new one (there would be a lot of overhead involved in instantiating all of the saved data).

    I know for a fact i could write my own serialization methods but i figured there would be a more elegant solution to this. If anyone can help, i would be very grateful.
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
  3. twoski

    twoski

    Joined:
    Mar 27, 2014
    Posts:
    27
    I have the UnitySerializer you linked, however it doesn't seem to do what i need.

    I just need some way to read entity data from a file and assign that data to an existing entity instead of instantiating one.
     
  4. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Well, at a very minimum, you'll have to have all the GameObjects and their components already there, and a way to line them up with appropriate read-ins, which kind of begs the question, what data exactly are you reading? Are you sure you're not better off just grabbing the tidbits you need?
     
  5. twoski

    twoski

    Joined:
    Mar 27, 2014
    Posts:
    27
    I have an entity which is essentially a container for a 2d array of other entities (tiles, to be specific).

    I want to be able to save those tiles as binary/json/whatever. Then when i read it back in, instead of instantiating a new 2d array of tiles i would just read the tile data and apply it to an already existing 2d array of tiles.
     
  6. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    That's pretty much what I'd guessed. My question remains - what makes these tiles special? If they're types - grass, wall, rock, etc. - you could probably just save a two-dimensional array of integers and apply them as sprite selections and behavior parameters.
     
  7. PrefabEvolution

    PrefabEvolution

    Joined:
    Mar 27, 2014
    Posts:
    225
    If you want to save just this "array of tiles" just serialize/deserialize them using XmlSerialization or BinnaryFormater