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

How we superseded Army's expectations with a Drone Op

1/23/2017

Comments

 
Picture
This is a two part blog post. Part 1 talks about the background to the entire exercise, the Part 2 talks about the simulation exercise which was built on top of the entire Drone Op generated data.
 
The background to this entire operation were our simulation activities that we were doing for Defence. Our past experience had mostly been with the Indian Air Force, and recently had also done some aviation simulation works for the Indian Navy. However when we demonstrated the same to the Army, the feedback given was ‘Well, all this simulation, terrain recreation etc is fine for aircrafts flying thousands of feet above the ground, but we need something which can give a soldier a feeling of if he has the boots on the ground’. This needed a very highly accurate ground mapping which required two elements – a digital elevation map (known as DEM) and ground texture.
 
Now DEMs were available, but those in the public domain had extremely low resolutions, only suited for very high-altitude passes, like those available from NASA and Japan Space Systems. Higher resolution DEM imagery is either available only to military (including ISRO’s own DEM data – but we didn’t have access to that), or very expensive to buy for commercial use.
 
Google earth (including Pro) pack – while allowed you to export imagery, it didn’t allow you to export the elevation, and even imagery had to be stamped with Google earth’s logo. And the resolution wasn’t good that we wanted anyway.  
 
The target that had been give to us for the textures resolution was – 10 cm per pixel. A massively ambitious target. But audacious goals only embolden us to achieve them. We decided, we’d get our DEM via an aerial survey.
 

Choice of platform

In order to do an aerial DEM, we obviously needed an unmanned aerial system (UAS), or commonly known as – Drone. There were many choices and factors
  1. Fixed wing (like your typical aircraft configuration) or Rotory
  2. Within rotory – tricopter/quadcopter/hexacopter/octacopter
  3. Choice of frame – plastic, carbon fibre etc.
  4. Choice of motors and propellers, and electronic speed drives to run them.
  5. Choice of controller – This was a major choice, with top two contenders being DJI vs APM (Ardupilot). This is like a choice between Apple (proprietary, closed system) vs Android (open source system)
  6. Payload – which cameras to take, including whether to use gimbals for stabilization or not.
  7. Final processing – after the data has been captured, how to process it and convert it into useful format ? 

Learning to fly

Picture
The first drone we had, we got a pre-assembled one based on the APM platform. The supplier had assured us that it was in ready to fly configuration, and you only had to power it up, and it was fit to fly. It wasn’t so easy as it turned out.
 
Picture
While we were very careful in powering it up, and had gone through all the relevant manuals, including some drone Sims, the drone just kept going rogue. We were unable to fly it either manually, or using the automatic mode. And with every crash, we had part breakdowns – most notably of propellers, and some cuts and bruises from prop hits.
Picture
We got to know the local drone parts supply ecosystems pretty well, which was vital to our later exercises. What we couldn’t get – we made. Our 3D printer was an invaluable tool, making prop-guards or coupling mechanisms so that we could fit those payloads which weren’t otherwise fitting on our Drone’s chasis.
 
But we still needed to get better at flying a drone, and for this, we got a miniscule quadcopter and the rotory flying guide – and learnt to fly this very gently – starting with a hop up, and then touch down, to eventually making it go from Pt. A to Pt. B as we wanted it to, mustering up our confidence in handling the actual operation.

Read More
Comments

Saving Data in Unity - Part 1

1/16/2017

Comments

 

Introduction

Saving and retrieving data is something that every Unity Developer has to struggle with at some point of time. By the nature of how Unity and how computers work, most of your data change is volatile. Even changes made in Editor Play mode are not permanent.
We need to save data in order to track progress and record important values, which are critical to the gameplay.
Data is lost between scenes because on every scene load Unity will destroy previous scene’s game objects, except when it’s explicitly specified. This in turn leads to destruction of MonoBehaviours and thus the data.
Data is lost between gameplay sessions because the memory allocated on RAM for a Unity application at run time is freed up by the OS when application is closed.
So the problem of saving and retrieving data can be broadly classified into two categories
  • Saving data between Scenes
  • Saving data between gameplay sessions
There are a number of ways of tackling each of these problems, some solutions are listed below:
Scene to Scene
  • Static class
  • Singleton pattern
  • Scriptable Object
Gameplay Session to Session
  • Player Prefs
  • Serialization to file
  • Database
  • Online
In part 1 of this article, methods of achieving data persistence between scenes will be discussed in details. Code snippets will also be provided when required.
In part 2, methods of saving data permanently will be discussed.

Read More
Comments

How the Indian Air Force got its game

1/6/2017

Comments

 
Picture
Guardians of the Skies, the official game of the Indian Air Force was launched about two years ago, and has gone on to be downloaded more than 3 million times, and won a couple of awards. Here is looking back at its story, which not only captures how it came into being and what went behind the scenes, but also a brief 'coming-of-age' of the small team which made it. 

You can get the game for Android, iOS and Windows. 

Why do we make games ?

​Games are supposed to be an escape from the reality, in a world of dreams. Where we can be what we wanted to be before we got caught up in the daily grind. 
When we started to make games, we had to ask ourselves - what do we make games about ?

If our players were to escape and role-play as some ideal character.. who could those be ? 
  • Who are our role models ?
  • Who safeguards our existense from external threats ? That our institutions are preserved and fundamental rights not under danger. 
  • Who are our Heroes ?
The answer was simple - the soldiers. And so we decided to make games on Indian military history. 
Picture

Read More
Comments

ACE-VR: Virtual Reality fighter aircraft game

3/31/2016

Comments

 
​Dear Readers..

On behalf of team Threye, allow us to share our first Virtual Reality game, something which we've been working across the year 2015-16, coming from the genre of aircraft simulators, you can enjoy missions like takeoff from aircraft carrier, land on sea/ground, engage enemy aircrafts etc. 

The current aircraft and missions available are based on a Mig29, it is planned to add more aircrafts, and more scenarios in future.

Meanwhile, please grab the beta here and give it a spin. For best experience, use a VR HMD and a joystick, but it works on standard PC with keyboard and gamepad as well.

​ACE-VR_Beta.zip
Comments

World photography day

8/20/2015

Comments

 
Picture
Dear Readers,

It happens to be part of our job to deal with electro-optical systems, the cameras, the sensors, the lenses and the drives. So here is celebrating the world photography day with an insight into just some of the equipment which we use for our various works.... from CSI board camera sensors to full frame DSLRs, with an assortment of lenses to match.

Happy shooting,

​Team Threye. 
Comments

Guardians of the Skies - Independence Day Special

8/12/2015

Comments

 
Picture
Dear Readers,

The official game of the Indian Air force - Guardians of the Skies, since its first release in July 2014, has gone on to achieve a total of more than 2 million downloads across various platforms, it has been featured on app stores across the world, and also won awards under Best-app and Best-game categories. 

We'd like to express our kind gratitude to all the patrons who've downloaded and played the game, and for those who wish to paint the sky with the Tricolour on the event of India's Independence Day on 15 August 2015, a special limited version of Guardians of the Skies has been uploaded on the Google Play Store with the mighty Su30 of the Indian Air Force in the Indian Tricolour Livery.

https://play.google.com/store/apps/details?id=com.threye.iaf.gots&hl=en

We hope that Guardians of the Skies has helped you feel the pride and the thrill of flying for the Indian Air Force, and hope that you continue to aspire to touch the sky with glory, and to help you keep close to that aspiration, are attached a few wallpapers to grace your screens.

Yours truly,
Team Threye. 

Comments

Augmented Reality Unity Tutorial - Part 3

11/23/2013

Comments

 
Comments

Augmented Reality Unity Tutorial - Part 2-B

11/23/2013

Comments

 
Comments
<<Previous

    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