Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

UI.Graphic inheritance + ExecuteInEditMode

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

  1. Galandil

    Galandil

    Joined:
    Oct 28, 2016
    Posts:
    13
    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:
    8,773
    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:
    13
    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