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

How to Move Text UI with Animation in Unity3d

I mostly prefer to tween UI but in this video i will show you how to animate text in Unity3d. most of the time you have to show some animated text and this game development tutorial exactly addressing the ui animation.


Control Object Transparency with Slider UI in Unity

In this unity game development tutorial you will learn how to control decrease or increase GameObject transparency/alpha or opacity. With the help of a slider and a C# script. I will explain how to increase or decrease opacity of an object using a c#  script. 

How to make Object Transparent in Unity3d with Script C#

C# Beginner Tutorials in Urdu/Hindi


I have started C#.Net tutorial series in Urdu/Hindi language and here are different lectures with the order.


1. Visual Studio Programming Environment Intro & First Script Execution

2. Visual Studio Programming Environment Intro & First Script Execution

3. Why start learning C# with Console Application Development

4. Variables in C# - int Data type - C# Beginner Tutorial Series in Urdu/Hind

5. C# Floating-point Numeric Data types | Float, double & Decimal | C# Beginner Tutorial Series

Unity Awake vs Start Event - Differences and Similarity


Unity MonoBehaviour offers different magic events that you can attach to any GameObject. In this unity tutorial I will explain awake or start events as they both mostly use for assignment purposes.

Awake:  Awake is invoked when the MonoBehaviour is created. You may view it as your default constructor
Start: Start event executes after all initialization is done and the first frame for the behavior is about to run. Start runs right before the Update event.
Similarity:
Start/Awake are called exactly once in the lifetime of the script.

How to Call one C# method from another C# script in Unity3d

Calling one method of a script from another script is common in Unity3d game development. In this Unity3d beginners tutorial I will show you how to call one c# method from another script.

How to add Serilog or Third Party Logging in Unity3d

In this video tutorial I have explained how to add third party logging system in Unity3d. This is advance logging way to log information in unity console with SeriLog. you can even write your games logs in specific text file with proper text formatting.

Linux Basic commands for beginners

#
Command Text
Description
1
Cd /
Go to root
2
Ls
Show all folder file directory names

Ls  -l
Show file permissions
3
Cd
Change directory

Cd ..
Go back one step
4
Mkdir directory-Name
Create directory
5
Touch app.txt
Create file
6
Vi app.txt
Edit file (vi default editor),
7
Insert mode
Press I to insert mode, escape to out
8
Cat app.txt
Show/print content
9
Cp app.txt  /home/faizan/desktop
Copy file to specific director
10
Mv file name directory
Cut paste
11
Rm file name
Delete
12
Man command name
Help how command work
13
Find search-path “filename with extension”
Find command for file
14
Find search-path -name “filename with extension or directory”
Search directory of file

How to Import NuGet package in Unity3d

You often require to add third-party dll or nuget packages in Unity3d project. In this unity tutorial I will show you step by step how to add Nuget Package or dll into Unity3d project. For this tutorial we choose newtonsoft nuget package. You can adopt these steps for any nuGet package.

Here are the details,
      go to your desired NuGet package webpage.
      on the right side **Download Package** option click it.
      your package **.nupkg** file will be downloaded.
      change its extension to .zip and extract it
      go to lib and copy your package dll file from net or any netstandard folder. For [your unity project compatibility purposes][2] view this:

      open unity workspace and create plugin folder
      paste your dll file here.

How to run Kafka Server with Producer and Consumer in Windows - Six steps Practical guide

In this post, we will learn that how to install and use Kafka server along with producer and consumer clients message exchange. This guide is based on practical only (no theory). For theory you can see other resources. This is the step by step practical guide that how to run Kafka on windows environment.

Step 1: Download and Extract Kafka in your desired directory:

1. Go to the link Apache Kakfa download and download. (I have download binary version 2.13)
2. Extract the .tgz file into any suitable location.




I have extracted my Kafka installation into C drive insdie Apachekafka Folder. 


Step 2: Install Java run-time and Save its path in environment variable.

1. Go to the link and install java runtime
2. After installation, open Environment variable from my computer properties and add JAVA_HOME variable and provide your java runtime installation path.

Java runtime installation path provided in a new environment variable named JAVA_HOME. 
3. In environment variable, select path, click on edit button and add this string  “;%JAVA_HOME%\bin”
4. Go to command line and test "java -version". If you are not getting java installed version then see

How to solve "npm not recognized as internal or external command"


Step 3: Run Apache Zookeeper and Kafka Server

1. Make a batch file next to your Kafka folder. This batch file will run Zookeeper server. Add below line and run the batch file

start kafka_2.13-2.4.1\bin\windows\zookeeper-server-start.bat kafka_2.13-2.4.1\config\zookeeper.properties

Note:In above batch file command, kafka_2.13-2.4.1 is my Kafka installation folder name put your folder name in both location.

2. Make a batch file for running the Kafka Server and Run the batch file

start kafka_2.13-2.4.1\bin\windows\kafka-server-start.bat kafka_2.13-2.4.1\config\server.properties

Note:In above batch file command, kafka_2.13-2.4.1 is my Kafka installation folder name put your folder name in both location.

Two batch files have created in order to run Zookeeper and Kafka Server. Whenever you want to run Kafka server, you first need to start zookeeper server.

Step 4: Create A Topic

In order to send message from Producer to consumer, you first need to create a topic. Later both producer and consumer will subscribe the topic and send and receive messages.

1. Go to Kafka installation directory, then Bin\Windows, and open command prompt form here and type below lines. You can write your desired name instead of YourTopicName
kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic YourTopicName
A topic with name "YourTopicName" has created successfully. 

Step 5: Start Producer

Kafka provides you message producer that will produce message for a specific topic.
1. Go to kafka installation directory, then Bin\Windows, and open command prompt form here and type below lines. 
kafka-console-producer.bat --broker-list localhost:9092 --topic TopicToSubscribe
Note: TopicToSubscribe is the topic name where you want to send messages, in our case it should be YourTopicName
2. Hit enter to start the producer

Step 6: Start Consumer

As name suggest consumer will get the messages from producer. 
1. Go to kafka installation directory, then Bin\Windows, and open command prompt form here and type below lines. 
kafka-console-consumer.bat --bootstrap-server localhost:9092 --topic TopicToSubscribe
Note: TopicToSubscribe is the topic name from where you want to gete messages , in our case it should be YourTopicName
2. Hit enter to run the consumer
3. Now go to Producer command line, and type any message and enter
4. View the Consumer command line you will get the message.


Unity vector graphics package missing solution

Unity Vector graphic package is in the preview stage currently so you need to check one more setting in order to view the package in the package manager window. First of all, you need to open package manager window from the Window menu then click on advanced setting and check show preview packages.


Unity Webgl Issues and Solutions

During my extensive interaction with unity WebGL, I found different things that are difficult to handle in unity WebGL or Unity Webgl has some serious limitations (But nevertheless I have managed to stream large 3D area in unity WebGL with asset bundles). I have made this post in order to show you Unity3D WebGL issues sheet and if you are interested to see what technologies or toolchain Unity WebGL using behind the Scene then check this post. So, without a particular order here is the list of unity webgl limitations with relevant references for your further research. 



1. You cannot use Threads in unity WebGL. Here is the error that you will get when thread try to start:
SystemException: Thread creation failed.
UnityLoader.js:4   at System.Threading.Thread.StartInternal (System.Security.Principal.IPrincipal principal, System.Threading.StackCrawlMark& stackMark) [0x00000] in <00000000000000000000000000000000>:0
GameDev Question
Unity Forum
Unity Webgl Doc
Update: Unity claim that in Version 2019.1.0 they have added multiple Multithreading support but it was not working according to my test and now I also find this that there was bug with the problem which has fixed in Unity 2020.1.0 and Unity 2019.4.7 (untested)

2. If you are continuously pressing any keyboard input key and meanwhile you lost focus to WebGL canvas in the browser, the input will still work even after releasing the key. The situation may get worst in the Edge browser.
Ref:
SE Question
Maybe resolved in Unity 2019.3.0 but I have tested and still the same problem is happening.

Unity Tips and Tricks (Unity Shader Tips and Tricks) Part V

In this post, we gather different tips and tricks related to Unity Shaders.

Unity Shader Tips and Tricks











See Also:

Game Pause on error in Unity3d

For debugging purposes, you may require to pause the game on an error so that you can inspect the game situation. For this reason, you can follow these steps:

1. Write an error log in block of the code

    Debug.LogError("Exception occured");

And before running the editor open console and hit Error Pause in the console log.


The game will pause as any error occurred in the console.