- Home /
A method for locking a prefabs instance from being modified?
A common issue I keep running into is that with my Script Components I'll very often edit on the instance of an entity (in the hierarchy) when I mean to actually edit the prefab (in the project).
Since these are custom components, and I know how to write custom inspectors for them. Is there a way to make the properties only editable on the prefab?
Answer by Antony-Blackett · May 15, 2011 at 01:16 AM
Try using EditorUtility.GetPrefabType();
bool prefab = EditorUtility.GetPrefabType(target) == PrefabType.Prefab;
Then depending on prefab being true or false you can change the custom inspector fields to labels so they cannot be edited. Or simply don't set the result of a field on the object. Something like this:
int fieldResult = EditorGUILayout.IntField( "MyInt", myObject.myInt );
if( prefab )
{
myObject.myInt = fieldResult;
}
Your answer
Follow this Question
Related Questions
Jump back to Prefab in Project view when selected there 0 Answers
Why cannot I drag and drop a gameObject from Hierarchy to a prefab's slot in the Inspector? 3 Answers
Need to see the whole hierarchy of a Prefab in the Project Tree 3 Answers
How to auto-navigate project hierarchy to asset by clicking in inspector? (Doesn't work anymore.) 1 Answer
How can I access the 2nd tier of children on a prefab in the Project Folder Window? 4 Answers