2017.1f3-p2 [POSSIBLE] Bug Moving Inactive RectTransform

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.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestPos : MonoBehaviour {

  int pos;
  float t;

  [SerializeField]
  RectTransform rt;

  void Start () {
    this.pos = 4;
    this.t = -100;
  }

  void Update () {
    if (Time.realtimeSinceStartup - this.t < 1) return;
    this.t = Time.realtimeSinceStartup;
    this.pos += 1;
    if (this.pos == 5) this.pos = 1;

    this.rt.gameObject.SetActive(false);

    if (this.pos == 1) {
      this.rt.offsetMin = Vector2.zero;
      this.rt.offsetMax = new Vector2(100, 100);
    }
    if (this.pos == 2) {
      this.rt.offsetMin = new Vector2(0, Screen.height - 100);
      this.rt.offsetMax = new Vector2(100, Screen.height);
    }
    if (this.pos == 3) {
      this.rt.offsetMin = new Vector2(Screen.width - 100, Screen.height - 100);
      this.rt.offsetMax = new Vector2(Screen.width, Screen.height);
    }
    if (this.pos == 4) {
      this.rt.offsetMin = new Vector2(Screen.width - 100, 0);
      this.rt.offsetMax = new Vector2(Screen.width, 100);
    }

    this.rt.gameObject.SetActive(true);

  }

}

PS… no combinations of ForceRebuildLayoutImmediate or MarkLayoutForRebuild seem to help with this either. Once Unity misses the initial ‘move’, it appears to be gone forever and won’t flag for update again.

Just another bump here because this seems like a not insignificant bug and my last test code was too wordy (maybe)…

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestPos : MonoBehaviour {

  [SerializeField]
  RectTransform child;

  void Start () {
    this.child.gameObject.SetActive(true);
    StartCoroutine(MoveLater());
  }

  IEnumerator MoveLater() {
    yield return new WaitForSeconds(1f);
    this.child.gameObject.SetActive(false);
    this.child.offsetMin = Vector2.zero;
    this.child.offsetMax = new Vector2(100, 100);
    this.child.gameObject.SetActive(true);
  }

}

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)?

1 Like

crickets Unity?

Got the same behavior, but no workaround :frowning:
Bug affects objects that are !activeInHierarchy at a time if position change.

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 :

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)

!so, it is still not fixed even in 2017.3!

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 :slight_smile:

public RectTransform compassStrip;
public float latitudeCompass;
public float xposCompass =0;
public void setCompass(float Angle)

    {
        Vector3 pos = compassStrip.anchoredPosition3D ;
        latitudeCompass = BenjasMath.keepAngle0to360(Angle);
        xposCompass = BenjasMath.map(latitudeCompass, 0,360,xPosAtZero,xPosAt360,false);
        pos.x = xposCompass;
        compassStrip.anchoredPosition3D  = pos;
    }