Some issues while upgrade project from unity 2021.3 to 2022.3

i. the character will become freeze or go though the ground while the game play launches. But if wait a frame or a physical fixed update time – frame before create the characters, then the game works ok. I did not delve too depth here, just delay creating the characters with one frame. Call this line yield return null; before create characters.

ii. Some fields that referencing other prefabs become lost. This is a very strange bug, the prefabs are there, and the MonoBehaviour yaml text content are the same. May be some yaml text mismatch in the prefab, and unity 2022 can not parse it well, I guess. To fix such issue, I load all prefabs that under Resources folder and re-save it with unity 2021.3. This process can be done with following code.

	void ScanAllPrefabs()
	{
		int len = Application.dataPath.Length - 6;
		string[] files =  Directory.GetFiles( Path.Combine(Application.dataPath, "Resources") , 
			"*.prefab", SearchOption.AllDirectories);
		foreach(string file in files) {
			string assetPath = file.Substring(len);
			Debug.Log(assetPath);
			UnityEngine.Object obj = AssetDatabase.LoadMainAssetAtPath(assetPath);
			EditorUtility.SetDirty(obj);
		}

		AssetDatabase.SaveAssets();
	}

After you re-save those prefabs under unity 2021.3, then submit those changed prefabs. Now open the project with unity 2022.3, run the same script again, those prefabs will be saved to unity 2022.3 format. Now run with your svn tools to find changed prefab files, with beyond compare, you will notice those changes in file. Correct the missing reference in text by hand. After that those fields restored, and everything goes well.

iii. Some physical function with layer mask value as parameter. some one may give it with a fixed value, such as 512 for example. But a good way to handle it is by using LayerMask.NameToLayer("Floor") instead. A new layer name may be inserted in project layer list without the potential problems.

iv. difference between Resources.Load(path) and Resources.Load<Type>(path) , most of the time they are equal. You can use each one as wish without any limit. But in the following case, you will encounter some error. They are some different asset under the same folder with the same filename but with different file extension. Just as following

/Resources/bot/bot.mat
/Resources/bot/bot.png
/Resources/bot/bot.prefab

Can you guess what will return if you call Resources.Load("bot/bot")? If you want to get the prefab, what you should do? Well, here Resources.Load<Type>(path) come in. With the type macro specified, you know what you will get.

// get the prefab
GameObject botObj = Resources.Load<GameObject>("bot/bot");

// get the texture
Texture2D tex = Resources.Load<Texture2D>("boot/bot");

Here, I have a question for you. What will return for Resources.Load<Texture2D>("boot/bot"); if you get some asset just like following :

/Resources/bot/bot.mat
/Resources/bot/bot.png
/Resources/bot/bot.jpg
/Resources/bot/bot.prefab