[ShowInInspector] with private bools not updating the bool box

Issue #678 resolved
docsavage created an issue


When using [ShowInInspector] for a private bool field the bool box is visible but not updated to reflect true/false in play mode.

There is a strange issue where using [ShowInInspector] for private bools with some classes derived from abstract classes do occasionally update to reflect the correct value.

Reproducible using simple script attached.

Unity 2019.4.f1.

Issue on odin 2.1.12 and 3.0 beta personal.

Editor only mode is off.

Windows 10.

Comments (6)

  1. Tor Esa Vestergaard

    To clarify, the value does not update even when you mouse over/click the inspector to make it repaint?

  2. docsavage reporter

    Hi Tor Esa

    Thanks for the quick reply.

    You are right I have tried all but the simplest test. If I click in the inspector window it does update and show the correct value. It seems it’s not refreshing the inspector when the value changes. Is this normal behavior for [ShowInInspector] private and protected fields?


  3. Tor Esa Vestergaard

    Unity is very lazy about redrawing editor windows, and tries to avoid doing it. Changing a backing bool value like that is not something Unity can detect cheaply without checking everything every frame (not very performance compatible). You need to either tell the inspector window to redraw when you change the value (which can be tricky, actually, there’s no simple API for it), or you can make the inspector repaint constantly by doing something like:

    private void RedrawConstantly() { Sirenix.Utilities.Editor.GUIHelper.RequestRepaint(); }

    Keep in mind that this would affect your framerate in play mode while this inspector is open, since the editor is also being drawn every frame.

    Also, RequestRepaint() won’t work if you call it in your game code, as it only works when called during a GUI event (at the end of the event, the request is checked and a repaint is triggered for the current “context”, but when there is no current GUI painting context, it does nothing).

  4. Log in to comment