• 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 /
  • Help Room /
avatar image
0
Question by William_Goodspeed · Aug 27, 2018 at 11:17 AM · custom editoreditorguicustom inspectorproperty drawer

Draw rect color disappearing when any input is detected

Hey folks,

I've got a simply Property Drawer script, which, amongst other things, Draws a coloured Rect around the property. However, I'm having an issue that if I've got the inspector window in focus and then use the scroll wheel the colored Rects lose their color. In a few seconds the color returns to them, but if I scroll the wheel again then the color vanishes.

After testing this, it seems that the Rects disappear while any input is happening. So if I continue scrolling they won't appear until I stop. Same for clicking.

Script:

         public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
         {
             GUIStyle minStyle = new GUIStyle(EditorStyles.numberField);
             GUIStyle maxStyle = new GUIStyle(EditorStyles.numberField);
 
             float padding = position.height * 0.8f;
 
             Rect borderRect = new Rect(position.x,
                 position.y,
                 position.width,
                 padding);
 
             Rect areaRect = new Rect(position.x + 2,
                 position.y + 2,
                 position.width - 4,
                 padding - 4);
 
             EditorGUI.DrawRect(borderRect, Color.black);
             EditorGUI.DrawRect(areaRect, Color.blue);
 }


Screenshot, on the left is how it should appear and on the right is what happens if I use the scroll wheel.

Before and after scroll wheel use

drawrect-example.png (64.2 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by William_Goodspeed · Aug 27, 2018 at 11:43 AM

Ah okay, so I've got to the bottom of this problem, it's detailed in an answer here:

https://answers.unity.com/questions/1311926/texture2d-in-scriptableobjects-property-drawer-exp.html?childToView=1401566#answer-1401566

And the solution is to simply add this to the bottom of your Property Drawer class

         public override bool CanCacheInspectorGUI(SerializedProperty property)
         {
             return false;
         }
Comment
Add comment · Share
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

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

153 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Property drawer with multiple fields: only first field has prefab override implemented 1 Answer

Trying to add EditorGUILabels and am getting a couple errors. 0 Answers

What's a good way to handle 'serialization' of interfaces in Unity ? 5 Answers

Use placeholder text in CustomEditor 0 Answers

Unity Custom Editor: 1 True Bool Only Within A Group 1 Answer

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