Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Get sibling custom editor

Discussion in 'Editor & General Support' started by Shlizer, Dec 1, 2023.

  1. Shlizer

    Shlizer

    Joined:
    Jun 26, 2012
    Posts:
    12
    Hey.. I've got a strange question...

    I have few components on a GameObject and those have custom editors - is it possible to reach them from other custom editors? I mean - I'm asking how can I get custom component editor (inspector) reference to some other custom editor of a sibling component?
     
  2. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,105
    You can create an editor for a given type.

    I don't think you can easily "get" a specific, already existing editor. Imagine you have two Inspector windows open, that would mean you also have two instances of the custom editor running. So which one do you want? ;)

    If you need to exchange data between two editors, it needs to happen between the components. Eg one editor updates an Inspector value in a component due to some user input. Another editor just gets the other component's value and need not know about who or why the value might have changed.
     
  3. Shlizer

    Shlizer

    Joined:
    Jun 26, 2012
    Posts:
    12
    Oh.. that's a bummer.. I am basically trying to make a button that exists in component editor A that will show/hide components (set `hideFlags` to `HideInInspector`), but it isn't refreshing after that easily so I wanted to call `Repaint()` on each toggled component editor, but I can't reach them..
     
  4. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,351
    You can always just have some static delegate the editor's subscribe themselves to, and you invoke as needed.
     
    Shlizer and CodeSmile like this.
  5. Shlizer

    Shlizer

    Joined:
    Jun 26, 2012
    Posts:
    12
    Yea.. it feels like it must be done like that.. thanks =)
     
  6. Shlizer

    Shlizer

    Joined:
    Jun 26, 2012
    Posts:
    12
    Well.. it won't be that easy tbh =/
    I can't unsubscribe components (OnDestroy is called even when it's going to just be hidden) and even repaint won't repaint whole component (I guess it's for it's content gui), so basically it just acts random and it's not possible to keep handle for hidden component (after setting hideFlags reference becomes null)..