- Home /
Can I safely put a prefab asset into version control with Unity Free?
I would like to use prefab assets to store a bunch of project-wide settings, similar in concept to a GUISkin. Will the .prefab files play nicely with version control?
More specifically, are my .prefab files fully self-contained, with no dependencies on the contents of the Library folder?
Feb 7, 2011 -- Thanks to tertle and DaveA for your thoughts on this. I'm going to carry on with putting prefabs into version control and see how it goes. So far so good.
Note that I up-voted both answers, but didn't actually mark either as correct, since there's still no definitive answer beyond what I originally suspected. (tertle's answer was auto-accepted by the bounty engine.)
More details ...
I don't need to be able to merge file revisions, but what I'm worried about is that a prefab may have hidden dependencies on the contents of the scene database -- all that opaque stuff in the Library\cache and Library\metadata folders.
On our project, we have two git repositories -- one for the Assets folder (art and code) and one for the Unity scene database (Library folder and friends). The Assets repository is used normally -- we all check stuff in and out throughout the day. The scene repository is "special" -- one person at a time owns it, and must get latest before making changes (which is a pain, but lets us carry on with Unity Free a while longer).
We currently have a GUISkin asset that sits in the Assets repository. This seems to be working fine. Looking at the .guiskin file and a .prefab file with a hex editor, it appears they use the same serialization mechanics, so I'm hoping that they would also both work fine in our git repository.
Being able to use prefabs more extensively would be useful, as it would let us move more design activities out of the scene repository and into the Assets repository.
I did search Answers for relevant info, and found some concerns with version control and prefabs in particular cases, but no general description of the issues. Info and advice appreciated.
And related to prefab assets -- I've noticed that if I have a reference from a component in the Hierarchy to a prefab component in the Project, then Awake is never called on the prefab component. Is that expected?
You will run into troubles if you use newer or older versions of scripts. Prefabs that contains script components have external dependencies. The script is not included in the prefab because it can be used on other prefabs/gameobjects and every class/script have to be unique. If you setup references to other assets (assigning them to script variables) they are also external. If they aren't present in an older version you will get a missing reference.
In that case the dependency is from one asset to the other -- does the dependency relationship get stored in the Unity database (Library folder) or in the prefab itself?
Answer by tertle · Feb 01, 2011 at 12:28 AM
codinghero posted a method of using SVN on free here: http://forum.unity3d.com/threads/43876-can-I-use-subversion-to-manage-my-unity-files?p=279261&viewfull=1#post279261 The whole thread is a good read though.
That all said I don't think you'll have issues other than really long rebuild times to update metadata from assets.
Thanks for the link. The thread suggests that it ought to work, and amounts to what I said in my answer to this question -- http://answers.unity3d.com/questions/11075/how-does-unity-free-source-control-go-wrong. I guess my question is really whether a .prefab file is independent of the Library folder. I'll edit my question to clarify.
Answer by DaveA · Feb 04, 2011 at 01:19 AM
We have taken to exporting packages (along with the source), and putting them in SVN. Then import the package as needed. In theory that would wrap up any dependencies that the Library might be storing, right?
DaveA, I'm not familiar with packages, but selecting Assets > Export Package... it appears this just exports assets from the project folder, not game objects from the scene. $$anonymous$$y question is really about getting data (and its dependencies) out of the scene (and its Library folder) into the assets folder. Assu$$anonymous$$g all dependencies have been severed then revision control should work fine (ok, not merging, but that's a different problem). (Sorry if the question isn't quite clear.)
Ah, sorry I forgot the important step: $$anonymous$$ake a new scene, call it like 'Settings'. Load Additive from your main scene. Delete everything but the gameobject(s) you need (say, an instance of your prefab). Then export that scene as a package.
Hmm, ok. And then you import the package back into your scene to get the data back. Do you have a bunch of automation wrapped around your process? I can't quite imagine making our artists and designers do that manually.
At this point, no automation (we're all geeks), but we've considered it for sure. I was thinking about doing that and putting it on the script wiki, have not gotten to it, don't know if/where pitfalls lie.
Answer by yoyo · Mar 04, 2011 at 07:58 AM
I've confirmed that dependencies between prefabs, or from a prefab to any asset, are stored in the Library. You can see this by examining a .prefab file with a hex editor (such as hxd), and you will see paths to Library files, with those great long GUID-like file names.
A prefab containing "pure data" components (numbers, strings, vectors, basic types) is fully self-contained and plays nicely with version control, but prefabs containing asset references do not.
Darn.
I've got some ideas for a solution to this, but further experimentation is required.
Your answer
Follow this Question
Related Questions
Generate a connected list consisting of scriptable objects. 1 Answer
AssetDatabase.AddObjectToAsset is not persistent? 0 Answers
Getting properties on 'missing' things in Editor Scripts? 4 Answers
Why do my prefabs not have an Asset Preview? 1 Answer
A event on deletion of asset in the asset database? 1 Answer