- Home /
Disable editing of components in inspector
I have a motor script that allows me to change the values of the attached collider. I want to disable editing the collider component in the inspector completely so that only my motor script can change the values in the inspector. How can I achieve this?
@Dorscherl Have you considered creating the collider component via the motor script at runtime? When there is no collider in the first place in non-play view, it also cannot be edited. On a side note, what's your use case for wanting to prevent collider editing?
Answer by Bunny83 · Mar 10, 2020 at 09:55 PM
I haven't actually ever tried this but it should actually work:
void Reset()
{
this.hideFlags = HideFlags.NotEditable;
}
Note that this would only work for newly attached components of that type when attached in the editor or when you rightclick on an existing component and choose "Reset". If you want to attach this script during runtime you might want to add this line also to the Awake method.
Awesome! This perfectly allows me to disable editing of a component in the inspector. No more blind editing
Your answer
Follow this Question
Related Questions
Detecting GUI.changed using DrawDefaultInspector 3 Answers
Text in the scene is not being updated! 0 Answers
Is there an event being fired off when the Inspector is being resized? 1 Answer
How do I implement Draggable Properties with custom Labels in Editor or PropertyDrawer? 1 Answer
Script for a GUI button to change an object's rotation? 1 Answer