Keep custom handles always visible in editor

Currently working on a custom editor script, my handles keep hiding when I select an other gameobject which doesn’t have the script attached.

The question has already been posted but I couldn’t find a proper (complete and well explained) way of solving this. I’m trying to get the solution posted by @whydoidoit to work, but as long as Sceneview is not documented I am still struggling!

2 Answers

2

Well, I got it to work !

Here is the solution, replace your OnSceneGUI() function with CustomOnSceneGUI()

using UnityEditor;
using System;

[CustomEditor(typeof(BaseClass))]
public class BaseClassCustomEditor : Editor {
    
    void OnEnable()
    {
        SceneView.onSceneGUIDelegate += (SceneView.OnSceneFunc)Delegate.Combine(SceneView.onSceneGUIDelegate, new SceneView.OnSceneFunc(CustomOnSceneGUI));
    }
    
    void CustomOnSceneGUI(SceneView sceneview)
    {
        //Work here !
    }
}

Updated version: private void OnEnable() { SceneView.duringSceneGui += CustomOnSceneGUI; } private void CustomOnSceneGUI(SceneView view) { //your code here }

Do you have any solution for showing multiple gameobject handles in the Sceneview ?

Thanks for spotting that I changed that part in my code now. I tried replicating this with if statements instead of switch case with the exact same result. Separating the switch case to its own method apparently also doesn't work.

Thanks, you also need to remove the callback when done:

 private void OnEnable()
 {
   SceneView.duringSceneGui += CustomOnSceneGUI;
 }
  private void OnDisable()
 {
   SceneView.duringSceneGui -= CustomOnSceneGUI;
 }

 private void CustomOnSceneGUI(SceneView view)
 {
   //your code here
 }

This doesn't work for me, everytime I deselect my custom editor, the onDisable is being called. It just do its default behavior which is hiding when unselected.