- Home /
Vars on prefabs
I am building my own prefabs. When I initiate a prefab on my hierarchy, if I modify a var and after that I click on "Apply", all other instances of this prefab are changed too.
Is there any way to define a var whose value is not saved on the prefab even if I click on "Apply"?
Basically I would like to edit my prefab but also having "free vars".
Answer by DiegoSLTS · Apr 09, 2015 at 01:56 PM
You can't define a variable to not be updated, that's against the purpose of a prefab, anything that you haven't changed manually in the prefab is linked to the prefab values.
Anything that's not linked to the prefab value will be displayed in bold, you can "unlink" a field by changing it manually, even if you write the same value the field already has, or drag the same reference. Once the field is displayed in bold, changes on the prefab won't affect it.
Note that if you "apply" on the instance those values would be used as defaults and will be linked again to the prefab (the bold letters will turn to normal), so be carefull when applying changes. I always create an instance, make a change, apply, and delete the instance, so the instances that I actually want remain unlinked.
mmm, that's a pity. Let's say a have a weapon prefab and 10 instances with 10 difference values (strength for example). I want to edit the prefab and all the instance (resistance for example).
You are saying I can't do it, right?, ie, if I edit the prefab I'll lose my 10 strength vars, right?
One more thing @DiegoSLTS: There are some vars that always unlinked in prefabs: the Transform vars and others like the sprite name. I am looking for that.
I mean, the x, y and z positions can be modified freely. However, a var from a component cannot. Is it right?
Thank you.
That's because when you drop a prefab into the scene Unity changes the transform values. Look at the inspector, the fields are in bold.
If you right click on them and select "Return Value to Prefab" the fields are linked again.
To test this, create a prefab with a Cube, then add 2 instances of the prefab on the scene, one with the transform linked, and the other unlinked. Then changed the x position on the prefab (selecting the prefab in the project window) and only the instance that is linked will move.
About the strength example, if you manually edited the strength field of each instance (i.e., the field name is in bold), when you apply changes to a prefab, the instances will not be changed on that field.
@DiegoSLTS, that's exactly what I was looking for. $$anonymous$$aybe I just didn't make the question clear enough.
You are clai$$anonymous$$g that I can have vars synchronised with the prefab and some other "free", right?
Just to clarify:
If I want a var to be syncronised again (ie, be updated when the prefab is updated), I have to click on Revert, right?
If I have 2 vars manually edited (bold) and I want only one of them to be synchronised again, it's possible, since "Revert" will synchronised both, right?
@Tatanan When you select "Revert Value to Prefab" on a field it just unlinks that field on that instance (you don't have that option on the prefab itself).
I'm not sure if this answers your second question, I'm not sure if you meant "possible" or "impossible", but no, reverting a field in one instance of the prefab won't synchronize all the fields, only the one you tell Unity to revert. Note that fields like "Position" on the Transform component can be unlinked as a whole (right click on the "Position" word) or you can unlink individual values (right click over the "X", "Y" or "Z" label next to each field).
Your answer
