OnInspectorDisplayed callback

Issue #186 resolved
Jay Pavlina created an issue

I'd like to request a callback that would run once when an inspector is displayed. One use case is hiding the transform component. This would be the preferred syntax:

[OnInspectorDisplayed]
void OnInspectorDisplayed() {
     transform.hideFlags = HideFlags.HideInInspector;
}

If you can't do that, this is a good alternative:

[OnInspectorDisplayed("OnInspectorDisplayed")]
class MyClass : SerializedMonoBehaviour {
    void OnInspectorDisplayed() {
        transform.hideFlags = HideFlags.HideInInspector;
    }
}

And it should work on ScriptableObject too.

Comments (3)

  1. Tor Esa Vestergaard
    • changed status to open

    You can achieve something similar to this by simply having an OnInspectorGUI that runs on every inspector GUI frame and checks whether the state is as it's supposed to be, and corrects it if it's not. Actually adding this properly isn't entirely straight-forward (you'd need an "OnDeselected" as well, and that one's tricky). I'll leave this lying around for now as a reminder, but we're not committing to whether or not we'll add it yet.

  2. Antonio Rafael Antunes Miranda

    Added OnInspectorInit attribute that gets called once when the inspector is first displayed (available in Odin 3.0.1 and up)

  3. Log in to comment