- Home /
How to do not apply fields in prefab
Hi, i have prefab that i have to put many times in my game. This prefab has script with 4 public bools and enum. I change this fields depending on environment. When i changed (for example)collider size in prefab and applied it, i lose all my settings in other instances... I think it is no sense to make prefab for each combination. There is some way to make fields that ignore apply, like a position in transform? Please help me. Sorry for poor English and thanks in advance.
Thats how prefabs works, I don't think there is a workaround for this as far as I know, all objects in the scene that inherit from a prefab in your game folder will change automatically if you modify the prefab in your Assets folder.
$$anonymous$$y suggestion would be to not make prefab until you have what you want as base, they should be used only as drag and drop, then modify directly in the scene the other instances by script or in editor.
EDIT: You can alternatively build your own EditorWindow to instantiate the prefab in the scene with certain values, is a bit of work but you won't need to touch your prefab in Assets folder for the scene.
it is disaster :O, if i make prefab and my graphics want change texture in prefab i will have to set my variables from the beginning, on the other hand if i don't create prefab i will have to set texture in each instance ;(
Yeah I can feel you, sometime can be redundant, but as I saied do a research for custom inspector and windows, you can create your own editor window where you can instance prefabs or anything else with the settings you want. This is a place to start:
http://docs.unity3d.com/Documentation/Components/gui-ExtendingEditor.html
You can also trying making a script the on Start instantiate the prefabs with the variables you want at the position you want if you don't need a too dynamic system.
Another thing you should check if you have multiple scenes using that prefab the instances changes also there if you modified the one in Assets.
Thx for posting this question. The answer will help me in every working hour in the future.
Answer by Bunny83 · Feb 19, 2013 at 02:54 PM
As long as a value isn't changed it's linked to the prefab value. So when the prefab changes the value will change on all instances which have not modified the value themselfs.
To stop using the prefab value, change the value in the inspector on your instance. This will make the variable to show up in bold text which means it has been changed on this instance. For boolean values you can simply check and uncheck the value.
To revert this you can simply rightclick on the variable in the inspector and select "Revert Value to Prefab". This will link the value back to the prefab value.
edit
Just to make sure you understand how prefabs work.
It's not the prefab which applies something to instances. It'S the instance which links it's values to the prefab. So each instance which hasn't changed any of it's values will read the prefab values. Whenever you change the value on an instance it will become seperated from the prefab value and show up bold.
When you press the "Apply" button on a prefab instance you effectively replace the prefab with the current instance and link all values of this instance to the prefab.
So basically you have full control over any value as long as you understand the dependencies.
You can also separate an instance completely from the prefab by selecting the instance and go to the menu GameObject --> "Break Prefab Instance". This will completely disconnect the instance from the prefab.
ps: To change a value on the prefab you can simply select the prefab from the project panel and change the prefab directly.
If an object is too deep nested in the prefab you have to temporarily drag the prefab into the scene, do your changes, press "Apply" and delete the instance.
"To revert this you can simply rightclick on the variable in the inspector and select "Revert Value to Prefab". This will link the value back to the prefab value." - hah, this is exactly what i want. I didn't know about this option. It so simple... THX. With version control i can be safe if someone apply all prefab.
Wow! I don't how I have missed this. Been using Unity for over 2 years now and always struggled with prefabs. Even used extra assets from the store to handle it.
Thank you very much!