UI.Graphic inheritance + ExecuteInEditMode

I just noticed that when inheriting from the UI.Graphic class (and subclasses ofc) the script is executed in edit mode by default, as if it has the [ExecuteInEditMode] attribute even if it’s not written in the script.

Is this intended behaviour?

Since attributes can be inherited, it would make sense for UI.Graphic to be executable in edit mode - it allows developers to easily position UI elements visually, for example.

Additionally, since these components are generally designed to be used by other scripts, I think it’s a reasonable expectation that heavy processing would not be included on the UI element component itself, but rather by the script that makes use of the element.

So I’d say that this is probably the intended behavior, yes.

1 Like

The odd thing is that, in the documentation of the Graphic class, the [ExecuteInEditMode] attribute is explicitly written in the example script, and there’s no mention regarding the fact that it’s active by default. That’s why I asked. Thanks for the answer, I’m curious about an official answer by a Unity rep. :smile: