- Home /
 
 
               Question by 
               mhmad2212 · May 02, 2020 at 09:35 AM · 
                instantiateprefabmobilewebplayer  
              
 
              Prefab instantiating at wrong position in mobile
hello.my game is 2d. It works well when I run the game in unity editor but in mobile prefab instantiate position is wrong!!! my game parent is canvas and made by UI elements; please help me
 GameObject obj = Instantiate(tilePrefab,wordLine[i].GetComponent<RectTransform().anchoredPosition,Quaternion.identity);
  obj.GetComponent().SetParent(GameObject.FindGameObjectWithTag(WichWordLine(j)).GetComponent(),false);
 
               
                 
                untitled.png 
                (33.3 kB) 
               
 
              
               Comment
              
 
               
              Please provide some code and the canvas settings (Render mode, Scaler etc.)
Instantiate expects a world position. You are giving an anchoredPosition.
Try something like this:
 RectTransform obj = Instantiate(tilePrefab).GetComponent<RectTransform>();
 obj.SetParent(GameObject.FindGameObjectWithTag(WichWordLine(j)).GetComponent<RectTransform>(),false);
 obj.anchoredPosition = wordLine[i].GetComponent<RectTransform().anchoredPosition;
 
                 It didn't work on mobile. prefab position in mobile is mistake
Your answer