Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Bug UI image rectTransform.rect readable via script in GameMode, but not in build.

Discussion in 'UGUI & TextMesh Pro' started by Ne0mega, Dec 14, 2021.

  1. Ne0mega

    Ne0mega

    Joined:
    Feb 18, 2018
    Posts:
    768
    Everything works fine in Game Mode, but once built, there is no image.
    As in a UI image with a material in the UI.

    I tried every different order of operation, lateupdates, co-routine delays like WaitUntilEndOfFrame to get rect values, and it would often work in Game Mode, (working but sometimes throwing nulls), but eventually I coroutined and made sure order of operations was perfect, no null errors in Game Mode, but once in build, it shows default UI image (off center checkmark thing).

    So I finally told my UI image LayoutElement to "ignore layout". It looks sloppy, hidden behind other elements in the layout.. but finally, I see color and not the default image in the build, meaning it was able to get rectTransfrom.rect values. This must be because the rectTransfrom.rect is no longer "hidden" by the various layout groups manipulating it above it in heirarchy. (there are five various parent horizontal and vertical layoutGroups)

    So somewhere, for some reason, some rectTransfrom.rect's are not readable in builds, if they are using a layoutElement in a layout group. it's not readable if I yield return new WaitForEndOfFrame(), It's not readable if I tell it to wait for a frame or two. It's just not readable.

    EDIT:
    "child force expand height" in the parent vertical layout group, and "flexible width, flexible height" in the image's layout element is the culprit. I'd assume it is the same with "child force expand width" in the parent horizontal layout group.
     
    Last edited: Dec 15, 2021