Search Unity

UI.Graphic inheritance + ExecuteInEditMode

Discussion in 'Scripting' started by Galandil, Apr 25, 2017.

  1. Galandil

    Galandil

    Joined:
    Oct 28, 2016
    Posts:
    5
    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?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    6,396
    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.
     
    Galandil likes this.
  3. Galandil

    Galandil

    Joined:
    Oct 28, 2016
    Posts:
    5
    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. :D