Search Unity

Question UI element repositions on canvas update

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

  1. eclipse130300

    eclipse130300

    Joined:
    Dec 6, 2019
    Posts:
    34
    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;
    5.  
    6.     Vector2 myAncoredPos;
    7.  
    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
    upload_2020-8-25_14-45-7.png
    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

    upload_2020-8-25_14-58-14.png
    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.