Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
25
Question by Insane · Nov 30, 2010 at 10:51 PM · editorinspector

Editor: multiple Inspectors

Hi,

I would like to know if it s possible to show two gameobject properties in two different inspectors?

Thanks,

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Statement · Dec 16, 2010 at 04:34 PM 0
Share

Do you mean you want to show two game objects through editor script code you've written or do you just want to line up two inspectors that edit two different objects?

3 Replies

· Add your reply
  • Sort: 
avatar image
66
Best Answer

Answer by Ben 14 · Dec 16, 2010 at 03:33 PM

Actually it's possible, but not intuitive. Bear with me:

  • select your first game object
  • lock the inspector by clicking the small lock icon on the top right of the inspector window. This will keep the inspector displaying your game object when selecting another one
  • right-click the inspector tab. This should give you a context menu with a "Add Tab >" entry at the bottom.
  • Expand "Add Tab >" and select "Inspector".
  • this creates another inspector window, showing the same object - but this one is not locked.
  • select your other object, and voila it displays in the new inspector window.

Hope this helps

Ben

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Glen_Hunter · Apr 03, 2015 at 05:00 PM 1
Share

Thanks! Really useful!

avatar image Pulov · Apr 23, 2015 at 10:06 AM 0
Share

wow! thank you!

avatar image DaveRohrl · Dec 14, 2016 at 06:30 PM 0
Share

Thanks! This tip saved me so much time!

avatar image
13

Answer by vexe · May 30, 2014 at 12:06 AM

Based on @Ben-14's work-around, here's how you create a new inspector window inspecting a certain target gameObject from code.

  /// <summary>
  /// Creates a new inspector window instance and locks it to inspect the specified target
  /// </summary>
  public static void InspectTarget(GameObject target)
  {
      // Get a reference to the `InspectorWindow` type object
      var inspectorType = typeof(Editor).Assembly.GetType("UnityEditor.InspectorWindow");

      // Create an InspectorWindow instance
      var inspectorInstance = ScriptableObject.CreateInstance(inspectorType) as EditorWindow;

      // We display it - currently, it will inspect whatever gameObject is currently selected
      // So we need to find a way to let it inspect/aim at our target GO that we passed
      // For that we do a simple trick:
      // 1- Cache the current selected gameObject
      // 2- Set the current selection to our target GO (so now all inspectors are targeting it)
      // 3- Lock our created inspector to that target
      // 4- Fallback to our previous selection
      inspectorInstance.Show();

      // Cache previous selected gameObject
      var prevSelection = Selection.activeGameObject;

      // Set the selection to GO we want to inspect
      Selection.activeGameObject = target;

      // Get a ref to the "locked" property, which will lock the state of the inspector to the current inspected target
      var isLocked = inspectorType.GetProperty("isLocked", BindingFlags.Instance | BindingFlags.Public);

      // Invoke `isLocked` setter method passing 'true' to lock the inspector
      isLocked.GetSetMethod().Invoke(inspectorInstance, new object[] { true });

      // Finally revert back to the previous selection so that other inspectors continue to inspect whatever they were inspecting...
      Selection.activeGameObject = prevSelection;
  }


 // Now you just:
 InspectTarget(myGO);

This is an editor script so you need to add using UnityEditor; as well as System.Reflection for the BindingFlags

How did I know about this? Simple, by decompiling UnityEditor.dll and lurking inside. I personally like ILSpy, there's also JustDecompile, dotPeek and (now the infamous) .NET Reflector

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image clunk47 · Jun 02, 2014 at 06:46 PM 0
Share

Thx man!

avatar image Dave_Voyles · Jul 05, 2014 at 03:26 PM 0
Share

How do you actually use this now? I created a new class called "DualInspectorWindows" and placed this in there, but I'm not entirely sure of how to use this.

Where does this go?

// Now you just: InspectTarget(myGO);

$$anonymous$$y class looks like this:

link text

avatar image vexe · Jul 07, 2014 at 08:19 AM 1
Share

@Dave_Voyles: Normally you'd just put this static method in a static utility class and just call it on a gameObject. In your case just do: DualInspectorWindows.InspectTarget(someGameObject);

avatar image
-2

Answer by ravin5432 · Aug 12, 2017 at 08:04 PM

Thank you for telling me about that lock!!! wow, made it so much easier

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Aug 12, 2017 at 08:39 PM 1
Share

@ravin5432 What you posted is not an answer. Also even as comment it's totally unnecessary to bump a thread that is already 7 years old... Just upvote the question and answer if you think it was helpful.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Arranging KeyCode type variables in custom editor 0 Answers

How to optimize a custom editor ? 3 Answers

[Solved]Why doesn't my ScriptableObject based asset save using a custom inspector ? 1 Answer

Custom Inspector Variables 1 Answer

Edit child in parent list [Custom Inspector] 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges