Unity project source control pollution

I’m using GitHub for source control.

The Problem
I have Texture Import Settings that wants its cube map setting to be serialized for 0 or 6. This is a sprite! We’ve never edited that property. But when it’s pushed by Person A, then Person B will push back the opposite unless these changes are discarded, which is annoying to remember to do. I obviously can’t gitignore our texture metadata.

I’ve had other similar problems, like a UI Prefab that sometimes wants its CanvasGroups to be serialized as 0 or 1 alpha, despite that prefab not even being opened.

Question
Is there a way to get Unity to play better with source control? I’d rather not switch services. We’ve tried having all people do a Full Reimport, which hasn’t worked.

It’s usually not Unity, but an issue with .meta files out of sync. Or quite simply you may not be using the exact same editor version eg everyone needs to be on 6000.0.27f1 and not various patch levels.

One of the most common cases where .meta files can go out of sync:

  • artist creates a texture in some image editing program
  • artist saves the texture from the image program into the project’s Assets folder
  • artist commits the change - just the texture file (xyz.png)
  • team members A and B pull the latest commit
  • A and B both open their projects with the next texture file
  • A’s Unity generates a .meta file for xyz.png
  • B’s Unity generates a .meta file for xyz.png
  • A checks in his changes including the new meta file
  • B checks in his changes including his new meta file
  • A pulls changes and finds that every reference to xyz.png is now “missing”
  • A fixes the missing references by reassigning them
  • A commits his changes
  • B pulls the latest changes
  • B finds all references to xyz.png are suddenly missing
  • B fixes the references by reassigning them
  • B commits his changes
  • A pulls the latest changes
  • A finds that … and so on

Perhaps you have an issue like that. The root cause being cases where a file under Assets is added without first opening the project in Unity in order to generate the .meta file for the new asset. I recommend writing a .git hook that disallows adding files under “/Assets/” if the file is not accompanied by a .meta file of the same name. This prevents many grievances.

In this case make sure that one user checks in his changes, then everyone needs to pull those changes and everyone opens the project with the exact same Unity editor version. From then on the issue should be a thing of the past.

There’s a chance that this issue is an actual bug. Sometimes (I’m just guessing but I’ve observed these in the wild) user preferences in the editor may affect how a file gets serialized and those parts of the asset keep changing for some users. If that’s the case, please report a bug.

2 Likes

This must be what you’re looking for.

1 Like

I would like to add one point, as I realized I had overlooked a simple possibility.

The second issue could be that the script is modifying the prefab.
Please note that any changes made to the prefab, even during Play Mode, will overwrite the asset and mark it with a dirty flag.
If the project is saved in this state, these changes will become permanent in the asset file.