- Home /
is it possible to apply changes to a prefab without changing the particular property values?
This is a question that is kinda hard to explain but I'll try my best: you see, I'm working on a game with 5 levels (scenes), each one of the have a special prefab whose properties I change in the inspector depending on which level the prefab is in.
It works great but the problem occurs when I decide to make a change to the prefab, no matter how tiny, maybe I just want to change the color of a material... when I press "Apply" all prefabs have this material changed..... BUT obviously the properties I changed in the inspector change as well!! This is a enormous pain in the butt because that means I have to go to each level AGAIN to change the properties in the inspector accordingly!.... my simple question is, is there any possible way to avoid this problem? say, I press the "Apply" button on my prefab, the material changes but the properties are kept as I modified them in the inspector in each scene/level?
geez, that was long... anyway, thanks in advance!
Answer by GameVortex · Jan 21, 2015 at 07:42 AM
Yes absolutely. What you describe is actually the default behavior of prefabs. When you apply a prefab, only unmodified properties will be updated on the other instances of that prefab. You can do a quick test and see for yourself.
1: Create an empty GameObject and add a Light component to it.
2: Make it a prefab.
3: Drag the prefab into the scene hierarchy (so you have two instances of it).
4: Change the light intensity value of one of the prefab instances in the scene. You will notice that the value and name is now displayed in bold. This indicates that unity has registered a change in the value.
5: Now change the light intensity of the other prefab instance to something else and hit apply. The value first goes bold and back to normal when applying indicating that the value is synced with the prefab.
6: Selecting the other prefab instance now you should see that the light intensity of that one is still the same changed value (not updated to match the prefab).
So what you describe is as I said the default behavior. It is usually wise though to only apply changes on the original prefab to serve as a template, or else one of the changed prefab instances in your scene you apply instead will be used as the template, with its other changed values.
Note: When you have a custom inspector for a component you have to tell it yourself that a value was changed by using: PrefabUtility.RecordPrefabInstancePropertyModifications. Or else the values will not be registered as changed and they will sync with the prefab.
you know what? you are totally right, I was being an idiot and what I was doing was modifying the base prefab ins$$anonymous$$d of each of the instances, I can see now that everytime I change a property of one of the instances it gets bolded which means it's now "protected" from the apply button. Thanks a lot!
Answer by ronshalev3d · Jul 08, 2019 at 01:21 PM
for those who see this question in unity 2019 today what you can do is to create a Prefab override with the specific changes you made. that creates a version of the prefab but without changing the basics.
unlike the concept of inheritance, where you create a version of a parent template, the override prefabs totally override the base prefabs and changes to the base prefab will be overridden by the changes you made in the version.
it is thus good to build the prefab as a generic template for all stages and then use the override versions as lvl1-enemy lvl2-enemy and so on to instantiate them in masses without too much hassle.
Your answer