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

Question [CustomEditor] that's active for child game objects?

Discussion in 'Editor & General Support' started by CodeSmile, May 22, 2023.

  1. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    I have a MonoBehaviour on a parent object and associated custom Editor script for the MonoBehaviour. The parent has several child game objects in the scene.

    I now have this case where I wish the parent type's custom Editor script would remain active even when one of its children is selected. Is that possible without duplicating the component or writing a custom editor for the children that shares code with the parent editor?

    The setup in the scene is like this:

    Parent (ParentMB + ParentMBEditor)
    -- Child1 (ChildMB + ChildMBEditor)
    -- Child2 (ChildMB + ChildMBEditor)

    I know I can keep a locked Inspector that has the parent selected, then select the children. But that is not a solution that works for me.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,610
    I imagine it's easy enough to do using
    Editor.CreateEditor
    for the parent and just draw that in the child object's editor?
     
    CodeSmile likes this.
  3. CodeSmile

    CodeSmile

    Joined:
    Apr 10, 2014
    Posts:
    5,533
    Thanks! I remembered CreateEditor but now I‘m thinkingit may be easier to write a custom base editor with shared functionality.If that doesn‘t workI can still plug it in as a created editor.