So I have been building a map editor for a game that our class is making. So far the results and power of Unity Editor has been great. The editor is built as an EditorWindow and edits and gets information form the Scene via a delgate added to
SceneView.onSceneGUIDelegate. For selecting objects I was using a ray cast to detect objects within the scene however that means that every object needs to have a collider on it to work. Looking at the HandleUtility again I saw and tried to use PickGameObject() , this I assumed was the way the basic Unity Editor does it, and guess what? Works perfectly, even gets object information from a gizmo which is perfect for a spawn point or the likes that is only a empty game object. Only problem is that I get two errors when this function is being called. I have looked up the errors and use of the function, my searching has not helped. The errors don’t crash the engine nor stop the function from working. Also a small black box appears at the tip of the cursor and lags behind when cursor is moved.
Errors
Error 1 - “GUI Window tries to begin rendering while something else has not finished rendering! Either you have a recursive OnGUI rendering, or previous OnGUI did not clean up properly.”
Error 2 - “device.IsInsideFrame()”
Code
//Function that is added to SceneView.onSceneGUIDelegate
void SceneGUI()
{
//creates very accurate ray based on raw mouse position.
ray = HandleUtility.GUIPointToWorldRay(mousePos);
//only gets an object if there is an object to look for
if(HandleUtility.RaySnap(ray) != null){
//gets the gameobject the mouse is over in scene view
hitObj = HandleUtility.PickGameObject(mousePos, true);
}
}
An idea about what the problem might be is that the SceneView class is already calling this function and since I am calling it in an added delegate in the SceneView it is causeing somekind of conflict. Of course no idea how to test that. This is a poorly documented feature of the HandleUtility so any help is greatly appreciated!