Search Unity

Canvas items render incorrectly in Editor Play mode at first and other oddities

Discussion in 'UGUI & TextMesh Pro' started by NYUnity, Feb 18, 2018.

  1. NYUnity

    NYUnity

    Joined:
    Aug 11, 2012
    Posts:
    8
    Hello all,

    I have a number of Canvas items in my UI that don't render properly in Play mode when the game is run in the Editor (2017.1.3 on Mac). However, if I SetActive(false) then SetActive(true) on the parent (in different Update calls, e.g., through a keypress that toggles the Active state), they render properly. They also render properly at game start when running the standalone Mac client.

    The hierarchy looks like:
    • Canvas
      • Container (the one that gets enabled/disabled) - full screen stretch
        • First Inner Container - attached to left side of screen, stretched between top and bottom with some margin in the Top/Bottom, with a Vertical Layout Group with a -100 spacing to overlap the inner items a bit
          • Items to display under here, using an Aspect Ratio Fitter in Width controls Height mode and an aspect ration of about 5/7 - all other leaf containers contain these same sorts of items (copies of the same prefab)
        • Second Inner container - attached to bottom of screen, stretched between the left and right, flush left and such
          • Third inner container - stretches to the full outer container, with a Horiz layout group that puts things in from (upper) left to right
          • Fourth inner container - also stretches to the full outer container, with a Horiz layout Group that puts things in from (upper) right to left
          • (These two things together can fill the bottom from the left and right to the center)
        • Fifth inner container - floats in the top right of the screen, with two more inner containers as the above, but with vertical layout groups
    Two odd things happen when hitting Play in the Editor, despite the Scene (with all the objects in the hierarchy above pre-instantiated for test purposes) looking perfectly fine in the Editor display before playing the game.

    1. The items in the inner containers rarely render properly, that is, the same way as they looked in the Scene editor, despite not being modified in any way programmatically. The rendering is incorrect differently each time I hit Play, with some rendering properly and others not. For example, in this most recent test, the items in the "Fourth inner container" above had their "Pos Y" modified to 0 (moved upwards) despite their starting position being at -150. In another run, everything is offset in the PosY across all containers. Again, hitting the key I have mapped to toggle SetActive on the main Container twice makes everything display/render correctly, without changing anything else. It works fine in standalone mode.

    2. Every time the player ends, the Scene is now marked modified (even if it were previously saved). Diffing the .unity scene file (thank you, Git) shows that a number of things have had their AnchorMin/Max and AnchoredPosition fields change. The Scene looks the same in the editor, however, and saving then playing again will mark the scene changed again. The number of things changed in this way is 18, which is also the number of actually displayed items in the various "inner containers" above. The next time I hit play editor, the scene is changed again after ending, and I hit "save" again, and this time the file is saved as identical to what is in Git already (the diff is now empty). This continues in this "changes things, save, changes things back, save," loop forever.

    I'm stumped. Can anyone give me any thoughts about what is going on here for both these oddities?

    Thanks!