OnSceneGUI() not working please help

hi

i have a problem with OnSceneGUI()
my scripts not working but Unity does not give errors
please help

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(Example))]
public class Example : Editor {

void OnSceneGUI(){
Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
Debug.Log( " " + ray);
}
}
Thanks

[CustomEditor(typeof(Example))]
public class Example : Editor {

I don’t know if you accidentally changed it to Example to show us, but you are creating a customEditor for an Editor. The first Example you have should be the name of the particular script you are creating the editor for, and the class name is usually the name of the target script+“Editor” (you don’t have to, but it makes it easy to know what editor is for what)

1 Like

Sorry i don’t understand you
can you give a script example please

Rereading my post, I can hardly understand what I’m trying to say :slight_smile:

[CustomEditor(typeof(LookAtPoint))]
class LookAtPointEditor extends Editor {
    void OnInspectorGUI () {
        target.lookAtPoint = EditorGUILayout.Vector3Field ("Look At Point", target.lookAtPoint);
        if (GUI.changed)
            EditorUtility.SetDirty (target);
    }

    void OnSceneGUI () {
        target.lookAtPoint = Handles.PositionHandle (target.lookAtPoint, Quaternion.identity);
        if (GUI.changed)
            EditorUtility.SetDirty (target);
    }
}

Taken from this reference page.

Notice how these:

[CustomEditor(typeof(LookAtPoint))]
class LookAtPointEditor extends Editor {

Are different classes.

If I have correctly understood you i renamed class to

[CustomEditor(typeof(ExampleEditor))]
public class ExampleEditor : Editor {

but script still not working

maybe i make mistake?

[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor {

There :slight_smile:

And I assume that you have a script named “Example” somewhere.

i have changed script to this but now i have 3 errors

The type or namespace name `Example’ could not be found. Are you missing a using directive or an assembly reference?

The best overloaded method match for `UnityEditor.CustomEditor.CustomEditor(System.Type)’ has some invalid arguments

Argument #1' cannot convert object’ expression to type `System.Type’

ok i was created script named Example
but script still not Logging ray direction

You don’t have a script named Example.

You need a script named Example.

i was created script named Example
but script still not Logging ray direction

Assets/Example.cs

using UnityEngine;
using System.Collections;

public class Example : MonoBehaviour {

	void Start () {
	
	}
	
	void Update () {
	
	}
}

Assets/Editor/ExampleEditor.cs

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(Example))]
public class ExampleEditor : Editor {

	void OnSceneGUI(){
		Ray ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition); 
		Debug.Log( " " + ray);
	}
}

Obvious statement is obvious but obviously this will only throw Debug.Log’s when the Example behavior is attached to a game object and that object is currently selected in the inspector.

2 Likes

its working!
thanks Mitch and Dman for help