- Home /
Can I change a prefab without changing the scene?
When I modify and save a prefab the .unity scene file also changes. Why?
In a team environment we need multiple people to be able to make changes to prefabs without having to modify the scene itself. Is this possible?
For example -- after changing a single numeric property of a prefab, six instances of which are in my scene, I looked at the modified scene file with a hex editor. It appears that Unity saves all the properties for each instance of a prefab, even if the property has not been modified from the original prefab value -- I found six numeric changes matching my edit. In addition, there are lots of other unidentifiable changes in the scene file, in what look like 16-byte GUIDs, perhaps asset references?
This begs the question of what happens if my prefab is instanced in more than one scene? Since only one scene is open in the editor, these other scenes won't be changed until later when they are loaded. Which makes it seem that the changes in the scene aren't necessary -- in fact I reverted the scene file in version control and it still loaded fine and got the new prefab settings. So if it doesn't need to be changed then why change it? Is it safe to ignore these changes?
Any advice on team-based prefab workflow is appreciated. (I've just upgraded to Unity 3.3 Pro, and enabled external version control, but I believe the same issue applies to Unity Free.)
Answer by Wolfram · May 24, 2011 at 09:34 PM
Yes, you can change the prefab in the Project view, without having to save the scene afterwards. We use that all the time, and it is a vital feature when several people are working on the same scene - we split sections of the scene into individual prefabs, which can be worked on and uploaded to the Asset Server individually, without the need for everyone to modify and update the scene as well.
When loading a scene, Unity updates any prefab changes on-the-fly, and integrates information about all(?) of the prefab's settings and parameters into the scene, even if they are unmodified default values. Therefore the scene is shown as modified, although nothing vital actually has changed.
Only if you do any local modifications to the prefab instance in your scene, or if you apply any previous local modifications do you need to save the scene as well.
This should also work if you change a prefab in the Project view that already has local modifications in one or more scenes.
Answer by Bunny83 · Mar 19, 2011 at 12:55 AM
My guess is since prefabs are an editor only feature in the end all prefab values will end up in the corresponding scenes at building time. There is still the original GameObject in the asset-database that will be used when you invoke Instantiate with a prefab reference but the prefab linkage is no longer available at runtime.
I think the changes won't hurt. As I said i think the changes will be made anyway to all scenes when you build your game. In the scene you always have the option to override any prefab values. These changes will also be saved in the scene.
Yeah, I think you do get the option to 'save changes' but that weather you do save or not the data in the scenefile will be identical. The metadata will be different before saving though, but this doesn't matter.
The scene file isn't identical, and it isn't the same size. There are a substantial number of differences in the binary file. Looks like I'll end up implementing an auto-dump to text file at asset save time, so I can see what's changed in prefabs and in the scene. ($$anonymous$$y Unity doesn't natively serialize to a text format.)
Answer by gekidoslair · Dec 06, 2013 at 09:17 PM
create an 'inventory' scene of sorts that stores all of the base prefabs, so you can manage / edit / work on the prefabs independently of working on the actual scenes that USE the prefabs.
As well, I'd highly recommend switching / setting all of unity's files to text instead of binary, makes merging any changes infinitely easier.
It's not really necessary to create such a scene just to edit your prefabs. Just drag them into an empty scene, edit, and apply. Or, for example if you're currently working on your main scene and have instances of prefabs with (necessary) local modifications in your scene but you just need to modify something in your prefab (that cannot be modified in the Project tab directly since that will only show the top two levels of a prefab's hierarchy), just drag the prefab from the Project tab somewhere into your scene. Then you can modify it, apply, and delete the instance again. Any other instances of that prefab in your scene will update at that point - but keep their local modifications.
Also, I fully agree on the text vs. binary thing. It would be a pain (or simply impossible) to compare and integrate changes of other $$anonymous$$m members without the text mode.
For sure, you can do that for one-off changes, but most of the assets that require prefabs in our title can be lumped into individual categories (for example the game 'characters' or 'vehicles' etc) that it does make sense to have an inventory scene of just for easy / quick reference.
Only challenge with merging might be if you have multiple people adding files to the inventory scenes at the same time - but again the text mode meta files actually allow most RCS systems to merge the changes somewhat sanely (and effectively). We haven't run into much problems with Subversion and/or Perforce (the two systems I've used this technique with).
Worst case scenario we've run into, you can save a copy of your local scene and 'copy / paste' any game objects into the main scene after syncing, but I've only needed to do this once or twice that I can recall.
Your answer
Follow this Question
Related Questions
How to turn off m_Modification for prefabs? 0 Answers
Handling scene objects 1 Answer
Can the "Apply" to prefab button be disabled? 1 Answer
Need of having prefab in Scene 1 Answer