Unity Json Serialization or Deserialization for Beginners

 In this tutorial, you will learn how to convert an object to JSON (JSON serialization) or Deserialization (JSON text to Object). This thing is often helpful to deal with response of reset APIs or database interaction related task or to save or interact with data in unity. Let's learn JSON serialisation in Unity3d step by step:

  1. Make  a class that you want to use as json, for example below I have created score class:

public Scores{

public int playerNo;

public string  playeName;

public string playerScore

}

2.     2.  Now if we want to make it work with JSON serialize. we have to use Serializable attribute in top of the class name

[Serializable]

public Scores{

public int playerNo;

public string  playeName;

public string playerScore

}

3.      3. Create objects of above class:

Scores scores = new Scores();

Scores. playerNo = 1;

Scores. playeName = “Faizan”;

Scores. playerScore = 100;

The object has created and now we are able to convert it to JSON text.

4.     4. To convert the Unity C# Object to JSON string, we can use the built-in static class of Unity named JsonUtility. Here is how it work

String jsonStr = JsonUtility.ToJson(scores);

Note that we have used ToJson method to convert object to JSON. The output of the above string will be like this:

‘{" playerNo ":1," playeName ":faizan," playerScore ":"100"}’

5.       Now if we want to convert the JSON string back to Normal C# Object (deserialization) we can use FromJson method of the same JsonUtility Class

  1. Scores jsonToObject = JsonUtility.FromJson<Scores>(jsonStr)

Not that jsonStr contains the full json string that we made in step 4.

This is smallest way to do JSON seralization and deserializatiin in unity without using any third-party plugins or dependency. If you don't want to use built-in Unity3d c# serialisation classes then you can also use third party plugins or nuGet package like newtonsoft. Here is the way to import newtonsoft DLL in Unity3d.

 

Python: can't open file get-pip.py error | Solution

 One of the common error python developers (new guys) face

python: can't open file get-pip.py error 

 

when they type python get-pip.py in CMD (command line). Despite the presence of the get-pip file in the Python installation folder like python/tools/scripts, we get the error sometimes. The common solution to the get-pip problem is to add your script's folder path into the Path variable.  

 

 


For Mac or Linux users you first required the command:

curl 'https://bootstrap.pypa.io/get-pip.py' > get-pip.py && sudo python get-pip.py

With this easy solution you won't get the issue again.

Unity WebGL Conversion Guide - Steps to consider For Unity Webgl Conversion

 There are some common steps you need to repeat whenever you make Unity WebGL build or if you want to convert your project into WebGL. Beware I am not using Unity 2020.

Learn more: Unity WebGL Technical Breakdown

1. Convert to Latest Unity Version (if Possible):

Always try to use the latest Unity version if you are building for unity WebGL as unity WebGL has several issues. With each new unity release, we see different bug fixes but remember each new build brings it known issues. If you don't have any problem with the latest unity version then, you should adopt it for your WebGL project. Beware porting to your current project into the latest unity version can show significant compatibility issues, so make a backup before conversion.

2. Save Scripting Define Symbols 

Before converting to WebGL please save your scripting define symbol outside unity (separately). Scripting defines symbols will be available under player settings. Some of the symbols are lost during WebGL conversion.
Scripting define symbols in webgl


Unity WebGL Technical breakdown - How Unity WebGL Works

 A Glimpse of technical background of unity3d WebGL:

Unity support dozen of platform for application deployment and one of them is WebGL. WebGL allows you to run your content on a web. Technically, WebGL is an API that renders graphics in web browser.  Currently, it has two supported version of WebGL 1.0 and 2.0. Remember WebGL 1.0 roughly matches the functionally of OpenGL ES 2.0 while WebGL 2.0 roughly matches the functionally of OpenGL ES 3.0.

Unity WebGL Structure


Figure 1 Unity WebGL consist of these components.

How Unity Render Streaming Work?

What is unity Render Streaming?

Unity render streaming is one of the packages/or a solution that allows HD rendering via a browser. For more clarification of the concept of render streaming, see the below video. Here you can watch that how we can access HD content into different devices (laptop, tablet or even mobile) via a URL. Remember, the processing will take place on one high-end PC while the different devices can get video streaming/audio or even get a remote control of the player.

This streaming solution work on top of WebRTC. WebRTC is a free and open-source project that allows RTC (real-time communication) between web and mobile applications. Luckily unity also provides its own render streaming platform called Furioos.

How to Setup Your Own Render Streaming in Unity3d

In the below video, I have explained how to setup your own render streaming.

Automatic MySQL Backup using Batch File on Windows

Backup of your database are important. You can do the backup manually but automatic backup with regular time interval are good and time saving. In this post I am specifically talking about Mysql. Unfortunately there is no free solution for auto Backup. SoThere is a simple workaround available on windows platform to make MySQL backup automatically and freely. For this reason, you require a batch file and you have to write a batch script. And here are the steps for Mysql Database auto Backup:

1. Create a backup.bat file
2. Open the file in notepad and add this

echo off 
start "" "C:\wamp\bin\mysql\mysql5.6.12\bin\mysqldump.exe(your my sql dump address)" --user root --password=(provide your db password here) databaseNameHere --result-file="D:\database backup location SqlFileName.sql" --database databaseNameHere


Now let's break down the string we have mentioned in the above file:

Post Processing and Unity WebGL

 A common question asked several times about unity post-processing and WebGL, why post-processing is not working on my browser or some of post-processing features are not working in browser: The reason is that post-processing works with WebGL 2 (Unity Forum). Unity WebGL Post processing doesn't work on WebGL1. If your browser and GPU support WebGL 2.0 then PPS (Post Processing stack) should work within your browser. Unity Support graphics API WebGL 1 and WebGL 2 and if Graphic API settings are set to auto then WebGL 2 will try to run first (if supported in the browser) :


Webgl auto graphic api

Remove Empty Unity Events - Do Empty Unity Events cause Performance Issues?

      You definitely have noticed this thing that whenever you create a new script in Unity3D, the Unity scripting template adds two methods or unity events by default. The two methods are Start () &Update ().
using UnityEngine;
using System.Collections;

public class MyCustomScript : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
}

How to create a Basic Glass & Mirror in Unity3D

In this game development unity tutorial i have explained how to create a glass or a mirror using reflections and shader settings.

How to Render Game View in Grayscale Mode in Unity3d

Welcome to another unity game development tutorial, today i will show you how to render your whole scene or game in grey scale mode. Gray scale mode help you to