- Home /
SceneView.onSceneGUIDelegate GUI sorting problem
I'm making some editor extensions and so far, I have a Non-MonoBehaviour (not editor) script (SceneViewEx) that adds some stuff to the scene view (using SceneView.onSceneGUIDelegate
in the script's constructor) and a custom editor for a Mono-Behaviour script (ItemEditor) that also draws some stuff to the scene view (GUI.Button at the gameobject's position).
However, for the gameobjects, I'm not using OnSceneGUI
because I want the buttons to always be visible, so instead I'm using OnDrawGizmos
and again, use SceneView.onSceneGUIDelegate
to draw the buttons (has to be OnSceneGUI
for them to be interactable). The problem is that the buttons for the Item components are being drawn on top of the SceneViewEx's GUI elements. I've tried GUI.depth
but it doesn't work at all. I suspect this is being caused by the Execution Order of the scripts, or to be more exact, the order of the delegate's listeners, however I can't set their Execution Order because they are not Mono-Behaviour scripts (I can set Item's order, but making it earliest or latest didn't change anything).
To sum up: SceneViewEx is a Non-MonoBehaviour script that uses SceneView.onSceneGUIDelegate
to draw on Scene View GUI, ItemEditor is an editor script which also uses SceneView.onSceneGUIDelegate
inside OnDrawGizmos
to draw interactable buttons in the Scene View GUI even when object is not selected. ItemEditor's GUI is being drawn on top of SceneViewEx's GUI and I don't want that.
Is there anyway to make ItemEditor's GUI draw behind SceneViewEx's GUI, or make onSceneGUIDelegate
execute ItemEditor's function first, then SceneViewEx's?
Answer by xxPillsxx · Aug 17, 2018 at 05:08 AM
Alright, after asking how to reorder the delegate's execution order, I ended up following that method. In the ItemEditor script, after adding to the onSceneGUIDelegate, I remove the SceneViewEx's OnGUIFunc then add it again, this ensures that SceneViewEx's will be executed last and thus drawn on top of everything else. Although this tank my editor performance quite a lot, it works.
Your answer
Follow this Question
Related Questions
Hint at Inspector variables that have tooltips 0 Answers
Better Unity Event UI 0 Answers
How can i create a pup-up menu like the one for choose the shader on materials in unity 2019? 1 Answer
Custom inspector difficulties creating a Box / Group like widget 1 Answer
Play Unity Editor from VSCode? 0 Answers