Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Michael CMS · Nov 06, 2012 at 08:40 PM · inspectoreventcustom editor

Custom editor makes inspector view act weirdly.

Hello,

I've created a script that ended up making my inspector view looking from the right way to a really weird way (pics bellow) :

Before

alt text

After

alt text

Needless to say I don't want this behavior. Where did I screw up so badly ?

Here is my custom Script code

 [CustomEditor(typeof(GameObject))]
 public class AutoSnapObject : Editor {
 
     
     
     void OnSceneGUI()
     {
         
         if (Event.current.type == EventType.KeyDown && Event.current.character=='p')
         {
             
             RaycastHit hit;
             
             GameObject go = ((SnapTarget)GameObject.FindObjectOfType(typeof(SnapTarget))).gameObject;
             if (go==null)
             {
                 Debug.Log("no snap target found");
                 return;
             }
             if (go==target)
             {
                 Debug.Log("currently selected object is the snap target");
                 return;
             }
                 
             
         
             Collider coll = go.GetComponent<Collider>();
             if (coll==null)
             {
                 Debug.Log("no collider detected at the snap target");
                 return;
             }
             GameObject targetObject = (GameObject) target;
             if (targetObject==null)
             {
                 Debug.Log("invalid cast");
                 return;
             }
             Vector3 normalizedDir = coll.transform.position-targetObject.transform.position;            
             if (normalizedDir.magnitude <0.04f)
                 return;
             
             normalizedDir=Vector3.Normalize(normalizedDir);
             
             coll.Raycast(new Ray(targetObject.transform.position,normalizedDir),out hit,Mathf.Infinity);
             
             targetObject.transform.position=hit.point + hit.normal*0.03f;
             targetObject.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
             
     
     
             Event.current.Use();
         }        
         
     }
     
 }

goodunity.png (13.3 kB)
brokenunity.png (11.5 kB)
Comment
Add comment
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

1 Reply

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

Answer by Michael CMS · Nov 06, 2012 at 09:23 PM

Ok Solved it by changing

[CustomEditor(typeof(GameObject))]

to

[CustomEditor(typeof(Transform))]

Anyone has any clues as to why using GameObject is causing this behavior to happen ?

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 Diet-Chugg · Nov 19, 2015 at 09:29 PM 2
Share

I believe on Unity's back end they have written a custom inspectors for the GameObject class and the Transform class. If you make a CustomEditor for those classes it overrides Unity's implementation of their custom inspector. By drawing their default inspectors you are telling Unity to not use their CustomEditor so ins$$anonymous$$d you get what would be serialized if Unity was using no custom inspectors

avatar image HunterAugust · May 14, 2016 at 06:37 AM 0
Share

Diet Chugg,

Do you know where one could find the gameObject inspector class? I found the transform inspector class but can't seem to hunt down the GameObject class.

avatar image Bunny83 HunterAugust · May 14, 2016 at 09:11 PM 0
Share

The "GameObjectInspector" class as well as the "TransformInspector" class are internal classes inside the UnityEngine.dll which you can't access without using massive reflection.

You really should avoid replacing the inspector of any built-in object, especially if you plan to release your editor extension for others. It was never intended and isn't recommended to replace the GameObject or Transform inspector.

If you just want to add generic SceneView code, use the SceneView class and the "onSceneGUIDelegate" to register a callback.

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

12 People are following this question.

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

Related Questions

(ArgumentException: GUILayout: Mismatched LayoutGroup.Repaint) when holding the Up/Down buttons of EditorGUILayout.BeginScrollView()!! 1 Answer

Overwrite the inspector window on Scene Asset heading chosen in the hierarchy window 0 Answers

Edit chosen material in the inspector for custom editor. 2 Answers

How to assign a rigidbody in custom inspector? 1 Answer

Assets folder gameobject image 0 Answers


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