Search Unity

Question UI element repositions on canvas update

Discussion in 'UGUI & TextMesh Pro' started by eclipse130300, Aug 25, 2020.

  1. eclipse130300


    Dec 6, 2019
    I have an issue cased by the fact that I cannot wrap my head around UI elements yet.
    I'am making a lobby for my game. As soon as player joins, the model and nickname have to be spawned above his head, and that is actually happens initially, via this short script placed on each info rect
    Code (CSharp):
    1. public class InfoPlayer : MonoBehaviour
    2. {
    3.     public TextMeshProUGUI nickTxt;
    4.     public GameObject addFriendsButton;
    6.     Vector2 myAncoredPos;
    8.     public void Initialize(string text, bool isMyPlayer, GameObject clampTogameobject)
    9.     {
    10.         nickTxt.text = text;
    11.         addFriendsButton.SetActive(!isMyPlayer);
    12.         transform.position = clampTogameobject.transform.position;
    13.     }
    14. }
    and everything looks like this
    You can see that I use empty gameobject as a placeholder, and as soon as player chooses pedestal, feed it into the function. Everything works fine at this point.

    But as soon as I minimize window, enable/disable component, etc. - doing anything that forces canvas to update, info signs shift to the right, as thought I've changed the pivot from mid center to mid left and repositioned rect again, like this

    I face this extraterrestrial behaviour for the first time, moreover it seems as EDITOR-ONLY issue, as I've tested it on mobile and everything worked fine. Help me out, who knows what is wrong, please

    p.s. Here I use camera canvas for info rects.