- Home /
Is there a way to prevent non-prefab objects from being linked in the inspector?
For example, if I have a class like this:
public class Foo : MonoBehaviour {
}
public class Bar : MonoBehaviour {
public Foo myFoo;
}
In the Inspector, I can select any Bar component and drag in any object to the myFoo field if it fulfills either of the following:
It is an object in the scene which has a Foo component attached
It is a prefab asset (from the Project window) with a Foo component attached.
I realize that attachments from assets are only available at Editor-time, not at runtime. However, in my case I would like to make sure that only prefabs (the second case) are able to be attached to the Bar's myFoo field.
I'm aware of PrefabUtility.GetPrefabType()
, which I could use to check whether the attached object is a prefab asset or not, and delete it if not; but is there a way to make sure that no non-prefab objects can be referenced in the first place?