0

When moving a disabled (gameObject.SetActive(false)) RectTransform, the 2017.x releases don't behave the same as 5.6.x did.

bad stuff

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

enter image description here

Seems like a pretty ugly bug... is this a known issue? Got a simple repro project case if it's worthwhile logging a bug, but hoping there's some justice in the world and I'm not the first to hit this.

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

  }

}
derHugo
  • 83,094
  • 9
  • 75
  • 115
slumtrimpet
  • 3,159
  • 2
  • 31
  • 44
  • PS... no combinations of LayoutRebuilder.ForceRebuildLayoutImmediate or LayoutRebuilder.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. – slumtrimpet Aug 01 '17 at 15:15
  • PPS... posted this on the Unity forums as well: https://forum.unity3d.com/threads/2017-1f3-p2-possible-bug-moving-inactive-recttransform.486149/#post-3167746 – slumtrimpet Aug 01 '17 at 16:47
  • I don't get why you need to disable and enable your object in the same update. The result should be the same, so why not just remove SetActive ? – FLX Aug 02 '17 at 15:08
  • I appreciate that, but the actual application isn't just a white background with four squares either. ;-) This is a distilled sample showing the behavior in question and wondering if this is a known issue. Not really a true sample of the logic in the core application. – slumtrimpet Aug 02 '17 at 17:50
  • Ok. Well, what if you do the contrary of your example ? Activating your object while you change it's offset and disabling it right after ? Sorry I have no other idea. – FLX Aug 03 '17 at 09:39

0 Answers0