This site uses strictly necessary cookies. More Information
X- Home /
Prefabs in git
Hi, guys.
My team experienced really unpleasant problem: we are storing some ui prefabs in our project, but every time someone saves scene he gets a bunch of prefabs, marked as changed in git. The problem is that no one is changing prefabs.
Has any one experienced this and found a solution?
Thanks in advance
I haven't seen exactly that problem, but if you're not vigilant with your use of the "File/Save Project" menu option, you can see similar symptoms, and this could be what happened to you.
In more detail, when you modify a prefab (e.g. press the "apply" button while editing it in a scene) Unity just caches the change in memory, and doesn't write it to disk yet. This is true for some other asset types too, such as ScriptableObjects.
So before checking into version control you must make sure you execute "File/Save Project" in Unity, which flushes these changed assets to disk - and also save the scene, of course, which does not generally happen automatically at any point.
If you don't do that then you can sometimes get symptoms like those you saw when later on Unity does write the prefab file to disk, e.g.:
1) you clone the repository 2) you create some prefabs, place instances in a scene 3) you modify and apply the prefab changes, but don't save the project 4) you commit the modified scene file and prefab files to the repository 5) time passes, you close Unity, open it again, edit unrelated files 6) you go to commit some new changes and now the prefabs are showing up as modified
The problem here is that the prefab changes from (3) were not saved to disk ready for the commit in (4). So the commit in (4) contained stale data.
The prefab files were saved at some point during (5), e.g. when I closed Unity or opened a different project. So now git shows them as modified.
So, this may not be what is happening for you, but I wanted to make it clear that if you're not vigilant with use of "Save Project" before committing changes, then you can see very similar symptoms, and it could be what happened in your case.
Something else you can do to track these problems is use text-based asset serialization (if you're Pro users) - then you stand some chance of being able to analyse the changes that git is reporting, and figure out where they might come from.
thanks for your reply :)
I understood how unity saves our prefabs. but even when I do "Save Project" git marks prefabs as changed. another strange thing that diff shows that prefab is unmodified. that is : git sees prefab as modified, but diff says that it's not.
and we're already using text-based serialization
There must be some difference or git would not claim to see one. Is it a CRLF issue perhaps?
agreed.
source tree shows that nothing is changed "unmodified file", but git says that this file is modified. take a look

Has anyone discovered a cause or solution to this problem? We're getting the exact same thing, using unity 5.3.3
I've tried searching around, but this seems to be the only post on the topic.
Answer by DaveHill · Jul 31, 2014 at 03:58 PM
This problem can be caused by a script modifying data in OnValidate(). If the data is modified unconditionally, it seems like the prefab will be marked as dirty in memory despite no changes actually being made. It will then be written to disk when the scene is next saved, triggering your source control plugin to mark the file for edit.
I've reproduced this effect using a prefab with a script containing this code:
#if UNITY_EDITOR
void OnValidate()
{
transform.rotation = Quaternion.identity;
}
#endif
The problem can be fixed by changing the code to this:
#if UNITY_EDITOR
void OnValidate()
{
if (transform.rotation != Quaternion.identity)
transform.rotation = Quaternion.identity;
}
#endif
I was also initially confused by the whitespace differences I saw in source control. I'm using Perforce on Windows with the settings set to sync from the server with native line endings (CRLF), but Unity always seems to always write text-based assets with Unix-style line endings (LF). That means that files last touched by source control may not have the same whitespace as files last touched by Unity.
Your answer
Welcome to Unity Answers
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Follow this Question
Related Questions
Can't drag and drop prefabs made by other people on my team (Git/Git LFS) 0 Answers
Does AssetDatabase.GetDependencies return unpacked prefabs as well? 1 Answer
Creating a scene: instantiating a prefab in a scene or use pre-instantiated prefabs? 1 Answer