transform.root returning wrong object Unity

177 Views Asked by At

I have a button that's instantiated as a child of a prefab, when using transform.root it does not return the desired object.

GameObject parentObj = this.transform.root.gameObject;

that is the line in question

I have used Debug.Log to verify that, when instantiated, the name of the object is CityCenter(Clone), while transform.root.gameObject.name returns CityCenter, meaning it is getting the non instantiated version of the prefab instead of the object that is currently in scene.

0

There are 0 best solutions below