Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

OnSceneGUI bug

Discussion in 'Editor & General Support' started by cloudcamaleoniv, Apr 15, 2015.

  1. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    I'm using Unity 5.0.0f4. Don't know if this is a bug, but... inside my OnSceneGUI method:

    ---------------------------------------------------------------
    1. public void OnSceneGUI() {
    2. Vector3 screenPos = ConvertScreenToWorldPos(Event.current.mousePosition)
    3. if (Event.current.type == EventType.MouseMove)
    4. {
    5. Handles.color = Color.green;
    6. Handles.CircleCap(0, screenPos, Quaternion.identity, 20); // This does'nt get called
    7. Debug.Log("mouse move");
    8. }
    9. Handles.CircleCap(0, Vector3.zero, Quaternion.identity, 20); // Outputs a white circle. Weird.
    10.}
    ---------------------------------------------------------------

    This is driving me crazy.

    a. Line 7 writes to console every frame the mouse moves. (that's okay)
    b. Line 6 IS NOT drawing the circle. (that's not okay)
    c. Line 9 DRAWS the circle, but it's color is white, despite of what Line 5 says.

    So, what the hell is happening? Is this a bug?
     
  2. hantaro

    hantaro

    Joined:
    Apr 10, 2013
    Posts:
    5
    Hey there,

    question b. Are you sure it is not drawing the circle? Maybe screenPos is not what you expecting it to be and it's being draw somewhere else. Because the code is right. Verify this by changing the position to Vector3.zero that you know it will be drawn in a place you can see.

    question c. Every time you call CircleCap you have to define the colour before it.
     
  3. cloudcamaleoniv

    cloudcamaleoniv

    Joined:
    May 17, 2013
    Posts:
    57
    Hi, thank you for your answer. The answer for 'c' makes sense, thank you a lot.

    But 'b' is still making me go nuts.

    So, changing the circle position (inside the if statement) to Vector3.zero still is not making the circle appear. This is the new code:

    1 if (Event.current.type == EventType.MouseMove)
    2 {
    3 Handles.color = Color.green;
    4 Handles.CircleCap(0, Vector3.zero, Quaternion.identity, 20);
    5 Debug.Log("This is weird!")
    6 }

    Line 5 keeps showing in the console everytime the mouse moves, which is fine. But the Circle in line 4 refuses to get drawn, which is very weird.

    Any ideas?