Search Unity

Why do all Canvas objects have prefab overrides?

Discussion in 'Prefabs' started by sarahnorthway, Jun 20, 2021.

  1. sarahnorthway

    sarahnorthway

    Joined:
    Jul 16, 2015
    Posts:
    78
    I'm trying to figure out why all the Prefabs on my scene that contain a Canvas are in a constant state of having an override that needs to be applied. As soon as I Apply it to the base prefab, the override appears again. It's causing problems with version control and multiple people editing one scene file.

    This could be something in my menu system code, but what I can't figure out is WHAT has changed. This is what the overrides popup looks like:

    wbIBmdvY9J.png

    It looks like this even with the Inspector window in Debug mode. Nothing is highlighted in bold to say it has changed. What Canvas variable might be changing that would cause the Prefab source to think it's in top-level mode while the Override shows sub-canvas/nested mode like this?

    Is this just known Unity behavior and I should give up trying to prevent it?
     
  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    Unity's UI just dirties stuff all the time. The layout components update the transform values of the RectTransforms in the hierarchy to match the screen size when eg. the game view changes size, and those values are serialized. Even when you don't change the game view size, the layout components still writes the same value as is already there, which can cause the system to think that the value is dirty.

    Values being dirty is what causes there to be overrides, so you can easily end up with tons of essentially bogus overrides by just opening the scene or entering play mode or whatever.

    You could report it as a bug, and they might fix it, but it's kind of a fundamental flaw in the implementation of the UI system that I don't think is generally fixable. So it's a bit of a whack-a-mole situation.
     
    sarahnorthway and kamicazer7 like this.
  3. kamicazer7

    kamicazer7

    Joined:
    Oct 27, 2012
    Posts:
    7
    What Baste said, in our case, I'd just suggest not applying override changes to objects at all, unless they are intended. Just use that as a rule of thumb for everything in unity, as things can and will change value for several reasons when using the editor.

    In case you really want to confirm what has changed (since not all values are serialized in the inspector, hence not getting the blue override tag) you can use your git diff or simply compare the .prefab file before/after change.
     
    sarahnorthway likes this.
  4. sarahnorthway

    sarahnorthway

    Joined:
    Jul 16, 2015
    Posts:
    78
    Hmm, yeah, I checked the diff and actually there are no changes being made to these Canvases. I guess it's as Baste said, it's writing the same value which is already there which marks it as dirty anyway.

    It seems to be other changes to the Transforms that are peppered all over the diffs and causing problems, and yeah they occur when hitting play or moving the camera (maybe from pixel perfect? Despite parent Canvas being in Screen Space).

    Yerp, I'm going to give up this game of whackamole. Thank you!
     
  5. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,338
    If you have a consistent case where you can:
    - enter play mode
    - exit play mode
    - have changes to positions
    - save
    - enter play mode
    - exit play mode
    - have changes to positions again

    Then that's a bug! I've sent bug reports like that before, and they did get fixed, so there's always a chance. You'll have to do the dance with sending the entire project first, though.
     
    sarahnorthway and kamicazer7 like this.
  6. kamicazer7

    kamicazer7

    Joined:
    Oct 27, 2012
    Posts:
    7
    Just throwing it out there because it happened recently with a colleague, he was getting massive objects changes listed in his git commit, however diff was empty with nothing detected, we investigated and there was indeed no changes to prefabs. So I asked him to commit those anyway and as soon as he staged the files, they vanished from commit. So in case your git is a bit cranky saying things have changed when they really didn't, try staging them just to make sure things are up to date on git.