Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bug Stretched RectTransform Changes Values for no Reason

Discussion in 'Immediate Mode GUI (IMGUI)' started by kjakar, Oct 2, 2023.

  1. kjakar


    Dec 7, 2013
    I will start by explaining the hierarchy.
    Game Object – Note: This is a prefab
    | -- Canvas
    | | -- Empty RectTransform – Note: This is the problem child!
    | | |-- RectTransforms are parented here at run time.

    Note: No code adjusts the valuse on the problem rect transform.

    The RectTransform is set up to stretch the whole canvas and move down 190 from the top. Every now and then when you load up the project the RectTransform will have just changed to be 95 from the top and 95 from the bottom with no other changes.

    At first this would happen in the editor, and when I made builds it would show up in the build, but I could just go fix the values in the editor and build again. But now even when the values are correct in the editor, they are adjusted to the same 95 top and bottom in the builds. This is really weird though because if you launch the application several times, eventually the UI will go back to normal (Note: This is only when the values were correct in the editor).

    I first thought that it had something to do with the editor not initializing the canvas properly on startup. I have my game view stacked with my scene view so when I open the project and the scene view is up, you cannot see the canvas until you switch over to the game view and back. I have not been able to recreate it doing this repeatedly though, so I think it's something else now.

    I noticed that when you have the RectTransform in the debug view there are three values that stand out.
    • Local Position Y is -95
    • Anchored Position Y is -95
    Now when you change one of these to 0 the other goes to 0 and when you go back to the inspector view the rect transform will be 95 top and 95 bottom. I suspect that this has something to do with it, but I have no proof of that right now. I have a gif of this attached to help with understanding.

    I read over the C# reference for RectTransform, but it was not very helpful as most of the RectTransform seems to be handled in C++.
    If anyone else has had this problem and figured out a solution please let me know!

    Unity Version is 2022.3.4f1
    Platform is Windows Standalone

    Attached Files:

  2. Bwacky


    Nov 2, 2016
    Hi, did you ever figure this one out? I assume Unity won't change much here since the new UI system is more of a focus now, but it feels like a clear bug. My rect transform randomly breaks after a few days of repeat scene opening and I can't figure out what might be causing it. It gets a bit moved during builds as well, which makes thinking incredibly annoying with tons of UI windows to check every time before I attempt a build.