Threye
  • Games
  • Research
  • About
  • Careers

Subscribe to our newsletter

Serialization in Unity

2/10/2017

Comments

 

Introduction

This blog will cover the basics of serialization and the three most common methods of serialization in Unity: JSON, XML and Binary.

Serialization is the process of converting an object into a form that can stored or transported easily. 
Objects are instances of classes and they are converted to a stream of bytes. This stream can then be stored as a file, saved onto a database or sent over internet to a web service.
The reverse of this process, converting a stream which can be a file or a string into an object is called deserialization.
Picture

​It's easier to understand it using a simple example. In this example, the player details need to be saved, so that when the players replays the game, the details are already available to them. They don't need to provide it on every game session.

When the player inputs his details into PlayerData object the state of the object is serialized and stored as a file. In the next play session the saved file is deserialized  to recreate or clone the same state of our object. JSON and XML are two common standard serialization formats and both of them are shown in the image below. These standards have their own pros and cons and will be discussed later.
Picture

Serialization is used extensively by the unity game engine itself for things like saving data of MonoBehaviours and scriptable objects, editor scripting, prefabs, instantiation, saving and loading your scenes etc. This post will only focus on the use of serialization that you may encounter in a game.

Uses of Serialization


  • Saving Game Data
          Saving game related data like save files, entities data and game settings
  • Web Based Services
          Using web based services like leaderboards, social features, facebook, twitter or google APIs
  • Separation of Data from Code​
          Data can be separated from logic and it's easier for the designers to edit data files
  • Creating Levels​
          Level Layouts, worlds and game scenarios can be saved in a compact form
  • Modding​
          It is easier for modders to edit game entities or even add new entities or gameplay to your game

JSON Serialization


JSON is the most preferred data exchange format for the internet. Web browsers and servers continuously use JSON to communicat between each other.
  • JSON stands for JavaScript Object Notation
  • Syntax for storing and exchanging data
  • JSON is text
  • Language independent
  • Lightweight data interchange format
  • Human readable and easy to understand
PlayerData Class

JSON Serialization and Deserialization
​
​
JSON Output
​

​

XML Serialization


  • XML stands for Extensible Markup Language
  • used primarily for storing or transferring structured data
  • The structure of XML is very similar to HTML
  • Human Readable

XML Serialization and Deserialization
​

XML Output
​

​

JSON vs XML


  • XML is considered more verbose than JSON, so the generated data file is bigger. That's why JSON is preferred for web based services
  • XML can handle complex data structures and relations
  • Serialization and Deserialization operation is more costly for XML compared to JSON
  • More APIs use JSON. Ex - facebook graph API, twitter API and google maps API
  • XML mostly preferred for desktop application, JSON preferred for mobile and web applications

Binary Serialization


​Binary serialization converts and object into a binary format, which is a byte stream.
  • Serialization operation is faster
  • The data file generated is compact and smaller is size when compared to JSON or XML
  • The data file is Non Human readable
  • Platform dependent, only works on .Net platform

Binary Serialization and Deserialization
​
Comments

LVC Simulation for the Indian Army

2/6/2017

Comments

 
Picture
​This blog post covers how emergent gaming tools and technologies have been used to make high-fidelity defence simulation, including LVC (Live, Virtual and Constructive) simulation which is the way ahead for most military simulators.
 
The LVC Simulation was done atop a high-fidelity terrain reconstruction which was mapped in-house via a Drone operation. The high-fidelity, one-to-one scale terrain already had about 30times the resolution available from Google earth, and was then made interactive and compliant with an LVC Simulation architecture where troops and tanks could train simultaneously. The concept was successfully demonstrated and highly appreciated, as part of CII & Indian Army’s Seminar on Simulation, conducted by the Army Design Bureau.
 
This is part 2 and concluding post on the entire exercise, and part 1 covers the aerial mapping of the terrain via a drone here. 

High fidelity synthetic terrain recreation

The attached graphic illustrates the entire pipeline of constructing the high-fidelity terrain for the simulation exercise. Major parts are further explained below.
Picture
  1. Primary processing
    1. The first level of processing is to take the drone camera payload imagery and drone flight data. By syncing the clocks of both, we have accurate position and orientation of each imagery, and then based on SFM (structure from motion), we can recreate the terrain below (please refer to blog post 1)
    2. The output data which we receive then, is a height map (Digital elevation map), a triangulated mesh, and an orthomosaic texture.
    3. These, by themselves, need further processing to make them game/simulation ready.
  2. Secondary processing
    1. Since game engines have their own terrain features, then either using the height map data from above, we can create the game engine’s terrain, or import that triangulated mesh as a substitute for ground, including LOD (level of detail support). An intermediate processing requires the ground to be separated from elements like vegetation, civil structures, or any element which grows/stands atop the terrain.
    2. Builtup and vegetation elements then need to be reconstructed atop the terrain – if the same is available in the library (which is increasing getting populated) of geo-typical assets like builtup structures of urban and rural localities of the area, and vegetation, which again is geo-typical of the terrain type.
  3. Tertiary processing
    1. Finally, all the dynamics are added – example, collision bodies on terrain and superstructures, including wind/weather simulation.
    2. Lighting is setup to reflect the time of day and weather.
    3. Characters, and vehicles are added, including AI for automatic navigation and movement.
    4.  And finally, application and user specific elements like networking, graphical user interfaces etc are added.  
The image below, shows the synthetic terrain (virtual) constructed via the above pipeline.
Picture

Read More
Comments

    Follow updates

    RSS Feed

    Categories

    All
    3D Printing
    Aerospace & Defence
    Augmented Reality
    Author AnuragRana
    Author-AnuragRana
    Game Development
    Robotics

    Archives

    February 2017
    January 2017
    March 2016
    August 2015
    November 2013


​
​SIGN UP FOR OUR NEWSLETTER

We send a few emails per month about updates on games, blogs and jobs. Please consider joining.
​ We value your email and do not spam. Thank You.  

GET OUR APPS

CONNECT WITH US

All rights reserved. Threye Interactive Pvt Ltd. 2021
  • Games
  • Research
  • About
  • Careers