Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 IHVD · Oct 13, 2015 at 11:58 AM · raycastingeditorwindowdrawinghandles

DrawWireDisc in scene from custom EditorWindow

Hi everyone! So I have been trying to get some kind of Mesh Painting plugin going on, but the problem is that I somehow just can't be able to get a DrawWireDisc going on. The purpose for the Handles.DrawWireDisc is to give an indication of where the user is going to be painting on. The arguments that I give to DrawWireDisc, have to be Vector3's. In the example on the lovely Scripting Reference, they say something about points. I know that it's about the points of the collider that is currently selected, yet I am apparently unable to feed them to the function. I tried to Debug.Log them, which worked, then I tried to feed them in the function, which threw a NullReferenceException to my head. NullReferenceException: Object reference not set to an instance of an object UnityEditor.Handles.DrawPolyLine (UnityEngine.Vector3[] points)

My code is listed below:

  [ExecuteInEditMode]
     public class MeshBrushDockEditor : EditorWindow
     {
         GameObject selectedGO;  // Variable for the currently selected GameObject.
         // And here comes the raycasting part...
     public Camera RayCam;
     public GameObject cameraHolder;
             Ray scRay; // This is the screen ray that shoots out of the scene view's camera when we press the paint button...
     RaycastHit scHit; // And this is its raycasthit.
 
     #if UNITY_EDITOR
     void Update(){
     SearchCollider();
     }
 
         void SearchCollider(){
     //scRay = HandleUtility.GUIPointToWorldRay(Input.mousePosition);
     scRay = RayCam.ScreenPointToRay(Input.mousePosition);
 
     if(Physics.Raycast(scRay, out scHit, Mathf.Infinity)){
         selectedGO = scHit.collider.gameObject;
         if(selectedGO){
                     //Debug.Log ("The points of " + selectedGO.name + " are " + scHit.point);
             Repaint();
             Debug.Log(scHit);
             Handles.DrawWireDisc(scHit.point, Vector3.up, 0.5f);
         }
         //Debug.Log(scHit.point); //Works!
         //Handles.DrawWireDisc(scHit.point, Vector3.up, 0.5f);
     }
 }
     #endif
 }

The code that I copied is listed below.

 if (thisCollider.Raycast (scRay, out scHit, Mathf.Infinity)) {
     // Constantly update scene view at this point 
     // (to avoid the circle handle jumping around as we click in and out of the scene view).
     SceneView.RepaintAll ();
     // Thanks to the RepaintAll() function above, the circle handle that we draw here gets updated at all times inside our scene view.
     Handles.DrawWireDisc (scHit.point, scHit.normal, _mp.hRadius);

so I am able to get the points to print out, but when I try to print them, it says that is has not been referenced to the instance of an object. Or am I doing it wrong and should I be using a Collider.RayCast, and am I simply too stupid for using Physics.Raycast...? I need this to work from within a Dockable GUI Window, with no script attached to the Scene itself. Why I chose this, is because this was going to be a bigger challenge than what I am used to, just putting scripts on empty GameObjects, but I think I went a bit too high over my head. Before messing up my code completely (after taking backups ofcourse), should I be using a different form of raycasting? Cheers,

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

0 Replies

· Add your reply
  • Sort: 

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

EditorWindow & Handles Position/FreeMove/... 1 Answer

(Solved) How to position Handles.DrawSolidArc() 2 Answers

Draw Camera to Editor Window 1 Answer

Using Handles class 2 Answers

Is it safe to call SceneView.RepaintAll() frequently? 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