Showing posts with label Unity3d. Show all posts
Showing posts with label Unity3d. Show all posts

How to enable Unity Collaborate

 In this unity game development tutorial, you learn how to enable Unity Collaborate step by step. This tutorial will show you step by step guide to enable/start unity collaborate in your unity3d projects.

Learn More: Unity Collaborate Limitations/Disadvantages

 Let's get started:

1. Open services

Step # 1 - Open Services

Step # 2: Turn on Collaborate Feature

Step # 3: Select Organization 

Step # 4: Select Organization and Create Project ID

Step # 5: Now Click on Collaborate Toggle



Step #6: Install Collaborate Latest Package.


Step #7: Select File that you want to update on server.

Step # 8: Write comment and publish.




Step # 10: Now you can check history.


Unity WebGL Gzip vs Brotli Compression

 Gzip and Brotli are the two data compression programs that you can use when building for Unity WebGL. If you don't know how to convert your project to unity webgl then feel free to follow my unity webgl conversion guide. You have option in WebGL to choose specific compression format or you can even disable the compression too.

HTML Table

Gzip Brotli
Build files are bigger Build Files siz is smaller
Faster Build time Slow build time
Natively support on all browsers using HTTP/HTTPS Natively support on Firefox & Chrome only with HTTPS

You can check compatibility on caniuse


Read More: Unity WebGL technical Breakdown. 

Encoding 437 data could not be found - Error in Unity3d Build

I was developing a unity3d application that was interacting with excel file using a u3d opensource pacakage. It was working fine in the unity editor. My excel data was showing in editor but after building for windows platform it was not showing excel data in unity anymore. I checked the debug logs of my standalone player and found below error

Uploading Crash Report NotSupportedException: Encoding 437 data could not be found. Make sure you have correct international codeset assembly installed and enabled. at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x0023f] in :0 at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToString (System.Byte[] data, System.Int32 count) [0x0000e] in <8e8fa28d216a43ec8dcb2258d1f7bf00>:0 at ICSharpCode.SharpZipLib.Zip.ZipConstants.ConvertToStringExt (System.Int32 flags, System.Byte[] data) [0x00022] in <8e8fa28d216a43ec8dcb2258d1f7bf00>:0 at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry () [0x0014a] in <8e8fa28d216a43ec8dcb2258d1f7bf00>:0 at (wrapper remoting-invoke-with-check) ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry() at NPOI.OpenXml4Net.Util.ZipInputStreamZipEntrySource..ctor (ICSharpCode.SharpZipLib.Zip.ZipInputStream inp) [0x00015] in <09654f5254b44255887f6f774978077f>:0 at NPOI.OpenXml4Net.OPC.ZipPackage..ctor (System.IO.Stream filestream, NPOI.OpenXml4Net.OPC.PackageAccess access) [0x00015] in <09654f5254b44255887f6f774978077f>:0 at NPOI.OpenXml4Net.OPC.OPCPackage.Open (System.IO.Stream in1) [0x00000] in <09654f5254b44255887f6f774978077f>:0 at NPOI.Util.PackageHelper.Open (System.IO.Stream is1) [0x00000] in <6fd7ca6bad364c5ea94149697e721400>:0 at NPOI.XSSF.UserModel.XSSFWorkbook..ctor (System.IO.Stream is1) [0x00026] in <6fd7ca6bad364c5ea94149697e721400>:0 at DataConverters.ExcelToCsvWithNpoi.Convert (System.IO.MemoryStream stream) [0x00015] in <092dda33cb1b4692b34f7feb073574ee>:0 at LoadExcelAndConvertToCsv.OnLoaded (System.IO.MemoryStream stream) [0x0000c] in <092dda33cb1b4692b34f7feb073574ee>:0 at DataLoaders.MemoryStreamLoader+d__0.MoveNext () [0x000e5] in <092dda33cb1b4692b34f7feb073574ee>:0 --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in :0 at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.b__6_0 (System.Object state) [0x00000] in :0 at UnityEngine.UnitySynchronizationContext+WorkRequest.Invoke () [0x00002] in <469e86e97fa2467ebffe49bbd6086325>:0 UnityEngine.DebugLogHandler:Internal_LogException(Exception, Object) UnityEngine.DebugLogHandler:LogException(Exception, Object) UnityEngine.Logger:LogException(Exception, Object) UnityEngine.Debug:LogException(Exception) UnityEngine.WorkRequest:Invoke() UnityEngine.UnitySynchronizationContext:Exec() UnityEngine.UnitySynchronizationContext:ExecuteTasks()

Encoding 437 data could not be found.

After making some research I found that Mono  does not include internalization by default that is required in the standalone application. So, in order to solve the error “Encoding 437 data could not be found. Make sure you have correct international codeset assembly installed and enabled” I have to copy two dlls into my projects plugins folder. The typical location of the dll files is

C:\Program Files\Unity\Hub\Editor\2019.4.27f1\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unityaot

 I was using unity 2019.4.27. So at the unity installation location (given above), copy I18N.dll and I18N.West.dll into the plugins folder. Or you can directly copy it to standalone build under data -> Managed folder.

How Unity call it's MonoBehaviour Method or Events like Update

 Ever wonder how the magic events of unity Behavior works:

void Awake()

{

 

}

 

void Start()

{

 

}

 

void Update()

{

}

// Or other unity magic events like OnEnable, OnDisable, Late Update, Fixed Update, etc.,

The simple answer comes into mind that maybe unity use reflections to find Mono Behaviour methods in order to call it every time or maybe they use override to those methods but apparently, this is not happening. So how it calls its event especially the Update event that calls on every frame.

The way unity3d Messaging system works its:

1.      Unity scripting runtime Mono or IL2CPP access MonoBehaviour derived (type) script.

2.      Look for magic events and cache it.

3.      Like if a MonoBehaviour derived script has an update event then the script will be added into a list (list of scripts) that will be updated on every frame.

4.      Now during gameplay, unity iterates over the list and fire the Unity events. This is the reason that if you make your event public or private they don’t get effected.

 


Library\PackageCache\com.unity.package-manager-ui@1.9.11\Editor\AssemblyInfo.cs could not be found | Solution

You may get dozen of errors like

Library\PackageCache\com.unity.package-manager-ui@1.9.11\Editor\AssemblyInfo.cs could not be found. 

1.       You may get the UI package may error After importing ui package. Now for the solution of the UI Package Manager problem. Follow below steps or watch my below guide:

  1.     Go to Window -> Package Manager
  2.    Click on package Manager UI
  3.    Click to Update the Package

The error will disappear, see the below video:

Library\PackageCache\com.unity.package-manager-ui@1.9.11\Editor\AssemblyInfo.cs Solution

Preview Package is Missing in Unity 2020.3 - Solution

 Unity provides two kinds of packages verified and preview packages. Preview packages are on the development stage therefore, you cannot directly access preview packages (like Job system) in Package manager or its search. Preview package is missing is a config problem that we will resolve in this post: Follow the below steps in order to solve preview package missing problem in Unity3d:

1.       Go to window -> Package Manager

 

 On Package manager windows select the Dropdown (given on left) and select Unity Registry option. (This will provide you the list of available packages provide by unity). Remember it will not include preview packages. Like at the moment Unity Jobs system on the preview stage, if you try to search it then you will unable to find it.


.      

 Now in order to enable preview packages to show in the list. Go to Edit-> Project Settings -> then click on Package Manager.  Now here selects Enable Preview Package checkbox.

     Go back to the Package manager window. Now you can see Preview packages are also showing along with verified packages. Preview packages are clearly visible with preview text in orange color.

5.       Search for your desired package like jobs and you will find the result.

 

2.      

 

3


4.  

                                                                        


Get Request in Unity C# | Get data from a URL in unity

 You often require to access a URL/API endpoint in order to get/post data or communicate to a web server. For this reason, unity provides UnityWebRequest Class. The class specifically designed to handle HTTP communications. It provides set of functions especially Get and Post function to deal with data retrieval and data post operations: Here are the ways to use it:

Get Request: A common way to access data from a URL. Suppose you are trying to get JSON data from a URL/API (given below) and here is our working example URL

https://jsonplaceholder.typicode.com/todos/1

void Start()

    {

        string getURL = "https://jsonplaceholder.typicode.com/todos/1";

        StartCoroutine(GetReq(getURL));

    }

 

    IEnumerator GetReq(string url)

    {

        UnityWebRequest req = UnityWebRequest.Get(url);

        yield return req.SendWebRequest();//wait until request competed

 

        if (req.isNetworkError)//if the networkerror is true then, there is an error.

        {

            Debug.Log("Error While Sending: " + req.error);

        }

        else

        {

            Debug.Log("Received: " + req.downloadHandler.text);

        }

    }


If you have json string then you can deserailze it. Here is the detailed tutorail.

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.

 

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


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.

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.

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#