Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Unity UI 2017.1f3-p2 [POSSIBLE] Bug Moving Inactive RectTransform

Discussion in 'UGUI & TextMesh Pro' started by slumtrimpet, Aug 1, 2017.

  1. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    When moving a disabled (gameObject.SetActive(false)) RectTransform, the 2017.x releases don't behave the same as 5.6.x did.



    I'm setting the RectTransform offsetMin and offsetMax via script here (while the RT is disabled) and as you can see, the inspector 'thinks' the rect is moving (the outline and RectTransform position data in the editor are updating) but the RT isn't physically moving on my screen. This bug isn't limited to the editor only however, same visible results in actual builds.

    Here's how it SHOULD look (and the exact same code worked like this in 5.6.x):



    Seems like a pretty ugly bug... is this a known issue? Got a simple repro project case if it's any help.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class TestPos : MonoBehaviour {
    7.  
    8.   int pos;
    9.   float t;
    10.  
    11.   [SerializeField]
    12.   RectTransform rt;
    13.  
    14.   void Start () {
    15.     this.pos = 4;
    16.     this.t = -100;
    17.   }
    18.  
    19.   void Update () {
    20.     if (Time.realtimeSinceStartup - this.t < 1) return;
    21.     this.t = Time.realtimeSinceStartup;
    22.     this.pos += 1;
    23.     if (this.pos == 5) this.pos = 1;
    24.  
    25.     this.rt.gameObject.SetActive(false);
    26.  
    27.     if (this.pos == 1) {
    28.       this.rt.offsetMin = Vector2.zero;
    29.       this.rt.offsetMax = new Vector2(100, 100);
    30.     }
    31.     if (this.pos == 2) {
    32.       this.rt.offsetMin = new Vector2(0, Screen.height - 100);
    33.       this.rt.offsetMax = new Vector2(100, Screen.height);
    34.     }
    35.     if (this.pos == 3) {
    36.       this.rt.offsetMin = new Vector2(Screen.width - 100, Screen.height - 100);
    37.       this.rt.offsetMax = new Vector2(Screen.width, Screen.height);
    38.     }
    39.     if (this.pos == 4) {
    40.       this.rt.offsetMin = new Vector2(Screen.width - 100, 0);
    41.       this.rt.offsetMax = new Vector2(Screen.width, 100);
    42.     }
    43.  
    44.     this.rt.gameObject.SetActive(true);
    45.  
    46.   }
    47.  
    48. }
    49.  
     
    Last edited: Aug 1, 2017
  2. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
  3. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    Just another bump here because this seems like a not insignificant bug and my last test code was too wordy (maybe)...

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5.  
    6. public class TestPos : MonoBehaviour {
    7.  
    8.   [SerializeField]
    9.   RectTransform child;
    10.  
    11.   void Start () {
    12.     this.child.gameObject.SetActive(true);
    13.     StartCoroutine(MoveLater());
    14.   }
    15.  
    16.   IEnumerator MoveLater() {
    17.     yield return new WaitForSeconds(1f);
    18.     this.child.gameObject.SetActive(false);
    19.     this.child.offsetMin = Vector2.zero;
    20.     this.child.offsetMax = new Vector2(100, 100);
    21.     this.child.gameObject.SetActive(true);
    22.   }
    23.  
    24. }
    25.  
    Result:


    That's pretty bad... right (the black square is 'this.child' in the above code, the selection outline in bottom left corner is the correct position and corresponds to the displayed RectTransform data coordinates... but the black square isn't moving)?
     
    daxiongmao likes this.
  4. slumtrimpet

    slumtrimpet

    Joined:
    Mar 18, 2014
    Posts:
    372
    *crickets* Unity?
     
  5. Llotar

    Llotar

    Joined:
    Mar 27, 2016
    Posts:
    14
    Got the same behavior, but no workaround :(
    Bug affects objects that are !activeInHierarchy at a time if position change.
     
  6. sixolar

    sixolar

    Joined:
    Jan 8, 2014
    Posts:
    37
    I've come across this problem too, really annoying and most likely a bug indeed.

    I hope that'll be fixed soon, in the meantime I think I found a workaround, just add this line after activating the object :
    Code (CSharp):
    1. rectTransform.Translate(Vector3.zero);
    where rectTransform is the RectTransform of the object moved, it seems not to work if it's a parent's RT nor if it's a child's RT and a parent has been moved... (sorry if that's not really clear haha)
     
  7. AIVIK

    AIVIK

    Joined:
    Feb 12, 2015
    Posts:
    14
    !so, it is still not fixed even in 2017.3!
     
  8. reckless_glitch

    reckless_glitch

    Joined:
    Nov 22, 2013
    Posts:
    14
    Having the issue that it is working until I load some levels. then it suddently stops working. Not touch things while loading levels helps. Anyway this is a problem guys, please fix it :)

    Code (CSharp):
    1.    
    2.  
    3. public RectTransform compassStrip;
    4. public float latitudeCompass;
    5. public float xposCompass =0;
    6. public void setCompass(float Angle)
    7.  
    8.     {
    9.         Vector3 pos = compassStrip.anchoredPosition3D ;
    10.         latitudeCompass = BenjasMath.keepAngle0to360(Angle);
    11.         xposCompass = BenjasMath.map(latitudeCompass, 0,360,xPosAtZero,xPosAt360,false);
    12.         pos.x = xposCompass;
    13.         compassStrip.anchoredPosition3D  = pos;
    14.     }