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

Animator states and transitions not saving between git branches

Discussion in 'Editor & General Support' started by bceyetech, Mar 5, 2021.

  1. bceyetech

    bceyetech

    Joined:
    Dec 12, 2019
    Posts:
    8
    Hi there,

    I'm not sure if this is the correct place, but in a few of my projects I'm having issues where Animator states and transitions are not saving between git branches.

    The initial Animator state and transition creations seem to save fine and travel between branches, but if I checkout a new feature branch then add more states/transitions to those already created Animators, save and commit, then merge with the parent branch, the states are saved in the project Assets but are removed from the Animator. Which, I then need to drag and drop the states from the project Assets then re-setup the additional transitions.

    My .gitignore very closely matches this: https://github.com/github/gitignore/blob/master/Unity.gitignore

    Am I doing something wrong? If so, do you have any advice? Thank you!

    - Windows 10 20H2
    - Unity v2019.4.14f1 and v2019.4.21f1
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,008
    Are you properly exiting Unity before committing? Or at a bare minimum doing Project-Save?

    Unity is extremely lazy about actually calling fflush() on files, so unless you are confident in the function of Save Project, it's always better to exit.

    To see what I mean, change any asset property right now, such as a slider on a Material.

    Without exiting Unity, note that in git there are no changes.

    Note if you now switch branches that cause a change to that underlying asset, you are now in this limbo where Unity has changes you made not committed to disk, and git has changed the target underlying asset out.

    I wish Unity would fix this and just freakin' fflush() all files immediately. This half-broken half-commit system has never saved a single person any lost work. This is 2021, everybody should be using source control already.
     
    Kaldrin and bceyetech like this.
  3. bceyetech

    bceyetech

    Joined:
    Dec 12, 2019
    Posts:
    8
    If I'm understanding you correctly, I notice that as well. So normally what I do is switch branches and bring Unity to back into focus, which usually prompts a reload of the scene. When I didn't do this in the past, I get merge conflicts with the scene meta, which is not always recoverable. Only after reloading the scene do I merge branches. Is that what you mean?
     
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    39,008
    Scenes get written when you press Save Scene, and usually that also saves other assets. Usually.

    Always safest to close Unity utterly before doing anything in git. Slower and annoying, but safer.

    I also try to never merge scenes or prefabs, which is easier said than done on a larger team, especially with longer-lived branches.

    Additive smaller scene chunks and more prefabs can help guard against this, and also for a long-lived prototype feature, it can be better to clone scenes/prefabs in the new feature, allowing main branch to work against the original scenes/prefabs, until you're ready to bring the feature back in, but that has costs too.
     
  5. bceyetech

    bceyetech

    Joined:
    Dec 12, 2019
    Posts:
    8
    Yeah, I get what you mean, but I have zero problems outside of Animators with git and Unity; scene data, prefabs, materials, etc. all save/commit just fine, just those pesky Animators.

    I'll try closing Unity completely to see if that works and let you know.
    Thanks for the suggestion!
     
    Kurt-Dekker likes this.
  6. bceyetech

    bceyetech

    Joined:
    Dec 12, 2019
    Posts:
    8
    @Kurt-Dekker Yep, saving the scene then closing Unity before committing seems to work, thank you! That's ridiculous and is a pain, but at least I don't have to try to reapply states and transitions. Thanks again!
     
    Kurt-Dekker likes this.
  7. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    46
    Can confirm, same problem, closing Untiy and all of sudden git registeres the changes. That might be the root of more than a few problems we had during dev... Thanks.