|

Change default C# Script template

Ever wonder how Unity decides what a new scripts should look like when you right-click > Create > C# Script? Easy! For Windows, just go to C:\Program Files\Unity\Hub\Editor\<Unity Version>\Editor\Data\Resources\ScriptTemplates and open up 81-C# Script-NewBehaviourScript.cs.txt (as Administrator!) and edit the file to your content. Now, when you create a new C# script, it will use this…

| | |

Speeding up Addressable Assets Loading

Are you using Addressable assets in your project? Is loading very slow, especially while pressing Play in the Editor? Make sure you are loading a list of Tasks and running them in parallel instead of individually waiting for each Task to finish. // get locations of all Addressables var locations = await Addressables.LoadResourceLocationsAsync(label).Task; // this…

|

How to use try/catch inside of a coroutine

Ever wanted to do yield return null inside of a try/catch block but your Compiler/Editor says NOPE!? I consider this a bit of a cludge, but it does the job: private bool result = true; private void SomeMethod() { while (result) { yield return StartCoroutine(DoSomethingCo()); } } private void DoSomethingCo() { try { fileStream.Read(…); catch…

|

Don’t compare floats or Vector3 variables directly

Since the float implementation in Unity is built for performance and not accuracy (which is why in the Editor you will often see weird values like 0.000000001 instead of 0), you should never compare float values with the equality operator such as: if (floatVar == 0.5f) { … } …otherwise the result will most likely…