I’m trying to create a list of Prefab for my uGUI but when i try to position the prefab it doesnt move to the position at all… if i check in the scene it’s at an other place completly… -561, 167, 0 … how do i move my prefab??
he’s a child of the current monobehaviour script.
for (var i = 0; i < SaveGames.Count; i++)
{
var savedGame = Instantiate(SavedGamePanelPrefab);
savedGame.SetInfos(SaveGames[i]);
savedGame.transform.parent = _loadMenuPanel.transform;
var rectTransform = (RectTransform) savedGame.transform;
rectTransform.localScale = Vector3.one;
rectTransform.sizeDelta = Vector2.zero;
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.position = new Vector3(14, 131 * 75, 0);
savedGame.gameObject.SetActive(true);
}
Nonsense. RectTransform inherits from Transform. So you can access the RectTransform with .transform
To the OP: Setting positions manually for UI elements gets a bit weird. Try setting the position first, before parenting. Then parent with Transform.SetParent and set the second argument to false.
See if using .SetParent(_loadMenuPanel.transform, false) helps. The second parameter will make it keep its local position (which you set in the line above it) - the default is to keep the world position instead.
Also, in this case, you may sidestep the issue entirely by using a Vertical Layout group on the parent, instead of setting each position by hand. This is what it was made for.