- Home /
 
 
               Question by 
               turkiyecng · Mar 30, 2015 at 09:16 AM · 
                uiprefabinstatiate  
              
 
              Unity UI prefab instantiation bug

Where is the problem after instantiation it has different position and scale factor GameCnt is a Canvas

               Comment
              
 
               
              Answer by Mangas · Mar 30, 2015 at 09:24 AM
To avoid scaling problems when instantiating a new UI component and setting the parent you have to use SetParent() with the parameter worldPositionStays as false:
 newInstance.transform.SetParent(original.transform.parent, false);
 
               Instead of:
 newInstance.transform.parent = original.transform.parent;
 
               More information here: http://docs.unity3d.com/Manual/HOWTO-UICreateFromScripting.html
Your answer