Cleaning up and Backup / Migrating existing Unity project into new one or another PC

Before starting always make Backups – you never know! Cleaning Up / Migrating as a project folder In general you will always need the folders Assets: Contains all the assets like your scripts, scenes, prefabs, 3D models, textures, sounds, materials, etc ProjectSettings: Contains project settings like e.g. physics, lighting,etc Packages: Contains a manifest.json describing which … Read more

Instantiate objects within the terrain area

I noticed that you are creating new instance of the Random class. Don’t do that with Unity’s Random API. Just use Random.Range to generate random numbers. As for generating random GameObjects on a terrain: 1.Find the X position: Min = terrain.terrainData.size.x. Max = terrain.transform.position.x + terrain.terrainData.size.x. The final random X should be: randX = UnityEngine.Random.Range(Min, … Read more

More organized way to call Coroutines?

This is very straightforward. Just use yield return SecondRequest(); or yield return StartCoroutine( SecondRequest());. The yield before the the coroutine name or StartCoroutine should make it wait for that coroutine to return before it continue to execute other code below it. For example, you have four coroutine functions that should be called sequentially: IEnumerator FirstRequest() … Read more

UnassignedReferenceException even though using the null-conditional operator

Unity has a custom way to check inspector’s references against null. When a MonoBehaviour has fields, in the editor only[1], we do not set those fields to “real null”, but to a “fake null” object. Our custom == operator is able to check if something is one of these fake null objects, and behaves accordingly … Read more

Copy files from Resources/StreamingAssets to Application.persistentDataPath upon installation

You can put the file in the Resources folder from the Editor folder then read with the Resources API. TextAsset txtAsset = (TextAsset)Resources.Load(“textfile”, typeof(TextAsset)); string tileFile = txtAsset.text; You can check if this is the first time the app is running with this. After that you can copy the loaded data to the Application.persistentDataPath directory. … Read more

Repeated serialization and deserialization creates duplicate items

The reason this is happening is due to the combination of two things: Your class constructors automatically add default items to their respective lists. Json.Net calls those same constructors to create the object instances during deserialization. Json.Net’s default behavior is to reuse (i.e. add to) existing lists during deserialization instead of replacing them. To fix … Read more

tech