question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

NaughtyAttributes don't work on custom Inspector Editors

See original GitHub issue

Normally if I define a custom PropertyDrawer with an Attribute and apply that Attribute to a field for a MonoBehaviour that has a Custom Inspector and I use EditorGUILayout.PropertyField(field); do draw that field in the Custom Inspector’s OnInspectorGUI() then the custom PropertyDrawer will still be used for that field in the Custom Inspector.

If I apply a NaughtyAttributes Attribute like ShowIf to a field in a MonoBehaviour then it draws as expected with the Default Inspector but if I have a Custom Inspector and draw that field with EditorGUILayout.PropertyField() it won’t use the custom NaughtyAttributes PropertyDrawer. Is there any way to get this to work inside a Custom Inspector?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
dbrizovcommented, Jan 19, 2020

Fixed in version 2.0.0. The attributes are now reimplemented with Unity’s CustomPropertyDrawer so they work in custom inspectors. There are some exceptions, however (like ReorderableList, EnableIf…). For these to work you need to call NaughtyEditorGUI.PropertyField_Layout instead of EditorGUILayout.PropertyField when you are creating your custom editors

3reactions
karmacod3rcommented, Apr 26, 2018

Hope this is not off topic: Only an incomplete solution, but I managed to get Attributes working in my custom editor by using NaughtyAttributes.InspectorEditor as base class. Only thing is that I needed to make InspectorEditor.OnEnable “protected virtual” so I could override. In my custom editor I override OnInspectorGUI and do what I need after base.OnInspectorGUI().

Read more comments on GitHub >

github_iconTop Results From Across the Web

NaughtyAttributes 2.1.4 documentation
NaughtyAttributes is an open-source extension for the Unity Inspector. ... The attributes that won't work in your custom editors are the Meta Attributes...
Read more >
dbrizov/NaughtyAttributes: Attribute Extensions for Unity
NaughtyAttributes is an extension for the Unity Inspector. ... The attributes that won't work in your custom editors are the meta attributes and...
Read more >
If you are like me tired of writing custom inspectors, try ...
If you are like me tired of writing custom inspectors, try Naughty Attributes. It's incredibly powerful, free and open source.
Read more >
How to get button shown in the inspector for method ...
I create instance of it in editor time. ... atrribute class and custom property drawer but I am not sure how to get...
Read more >
Discussion - to beautify the inspector
Naughty Attributes is useful for simple inspector stuff. If you need heavily involved custom editor work - and lets be real, every project ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found