- Home /
 
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,
Your answer
 
             Follow this Question
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