• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Romeno · Mar 16 at 10:44 AM · editorinspectoreditor-scripting

Custom Inspector (Editor) - override just one field control

Is there a way to override just one (or several field (controls)) in a custom Editor for a MonoBehaviour or any other inspector editable entity? I know you can use DrawDefaultInspector(); to draw all that Inspector is drawing by default for any non custom inspectable obejct but I want to change one of them and leave alone the others.

The suggestion to just redefine all of them in Custom Editor is not good as you need not only to implement all default logic except for just one field but maintain that Editor later when you change MonoBehavior to add new fields to add respecting controls as well.

More specifically I need to add a callback for 1 field to resize another object in the scene when the field changes.

I tried adding a duplicate of the control and added code on changing this new control. It works fine when I change the new control but when I use old control to change the field Debug.Log() does not fire. Here is my code so far:

 [CustomEditor(typeof(Tetris))]
 public class EdScrtiptTest : Editor
 {
     SerializedProperty startSpeedProp;
 
     void OnEnable()
     {
         // Setup the SerializedProperties.
         startSpeedProp = serializedObject.FindProperty("pieceStartSpeed");
     }
 
     public override void OnInspectorGUI()
     {
         var tetris = target as Tetris;
 
         DrawDefaultInspector();
 
         EditorGUI.BeginChangeCheck();
         EditorGUILayout.Slider(startSpeedProp, 0, 100, "Start Speed");
         serializedObject.ApplyModifiedProperties();
         if (EditorGUI.EndChangeCheck())
         {
             Debug.Log("Changed");
         }
     }
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

146 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to record hideFlags for Undo/Redo 0 Answers

Get default preview for GameObject Editor 2 Answers

OnInspectorGUI changes reset when played in editor or building 2 Answers

How can I make one variable affect others in custom inspector? 2 Answers

Get the highlighted variable in the inspector 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges