| | |

Unable to apply changes to a Prefab

Ever make changes to a Prefab in your Hierarchy and click in the Inspector under Overrides > Apply and nothing happens? That’s because your Prefab has at least one reference to something outside of the Prefab itself. Simply move these referenced objects/scripts inside the prefab (or delete the references to things outside of the Prefab…

|

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…

| | |

Asset Prefab preview image thumbnails are black, missing, outdated, or incorrect

Are you using Universal Rendering Pipeline (URP) and some prefab previews in your Project > Assets folders are black, missing (shown as blue cubes) or not reflecting changes you made to prefabs? Just right-click on one or more prefabs and select Reimport and wait a couple seconds. If the preview images are still black, missing…

| | |

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…

| |

How to show private variables in the Inspector

Click the 3 dot menu in the upper-right corner of any GameObject in the Inspector and click Debug: Afterwards you can see a lot more information about your scripts, including private variables:   Alternately, if you have the amazing NaughtyAttributes package in your project, you can use [ShowNonSerializedField] attribute: [ShowNonSerializedField]private float myHiddenVariable = 1f;

|

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…