• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by vivalavladislav · Jan 23, 2014 at 01:02 PM · prefabsgit

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

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image gfoot · Jan 23, 2014 at 01:20 PM 1
Share

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.

avatar image vivalavladislav · Jan 23, 2014 at 01:52 PM 0
Share

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

avatar image gfoot · Jan 23, 2014 at 02:05 PM 0
Share

There must be some difference or git would not claim to see one. Is it a CRLF issue perhaps?

avatar image vivalavladislav · Jan 23, 2014 at 02:52 PM 0
Share

agreed.

source tree shows that nothing is changed "unmodified file", but git says that this file is modified. take a look

alt text

untitled.png (22.5 kB)
avatar image SarfaraazAlladin · Mar 21, 2016 at 09:04 PM 1
Share

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.

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
3

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

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

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

How to calculate the Angle of incidence on a plane 0 Answers

Problem: Random Instantiating more than one prefab? 1 Answer

Prefabs do not unclude in build if not created directly in app 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges