Why my prefab's Scale is changed to 0 at runtime?

Here’s my code:

Vector3 posGirlBody = new Vector3 (0, 0, 0);
		GameObject girlBody = Instantiate (girlPrefabs [Random.Range (0, girlPrefabs.Length)], posGirlBody, Quaternion.identity) as GameObject;
		var crtScale = girlBody.transform.localScale;
		Debug.Log ("Current Scale is: "+crtScale);
		girlBody.transform.parent = transform;

The Debug shows: Current Scale is: (1.0, 1.0, 1.0), but in my Inspector, when I click on the prefab (clone), the Scale shows (0, 0, 0), and I can’t see the prefab in my game view, so it was in deed reset to 0 at runtime. How to solve the problem? Please help!

Okay so it’s a UI element, in Unity, when you change the parent of a transform, it must take into account all the parent transform scale and orientations into account. In this case, the described problem lies in the top-most parent which is “Canvas” which has a scale very close to zero (and probably rounds to 0 on parenting).

Solution is rather simple. After you parent it, set it’s local scale to 1 :slight_smile:

girlBody.transform.parent = transform;
girlBody.transform.localScale = Vector3.one;