Search Unity

Bug Easily reproduceable "Should not be capturing when there is a hotcontrol" bug

Discussion in 'Scripting' started by Omni_Owl, Nov 26, 2020.

  1. Omni_Owl

    Omni_Owl

    Joined:
    Nov 26, 2013
    Posts:
    176
    So I am trying to make a custom editor which hides away the Camera on a gameobject while leaving my custom component in-tact. However, no matter how I do it with my current setup I keep getting the dreaded warning (which really is an error that has been present for years):

    Code (CSharp):
    1. Should not be capturing when there is a hotcontrol
    2. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)
    So to try and figure out what the actual bug was I started eliminating possible factors down to the bone and eventually giving up on what could be causing it. But then it occurred to me that the simplest version of this extension should work and if it does, I can work from there (spoiler: it didn't work and this is why I'm writing this report now). So I setup the following two classes:

    Code (CSharp):
    1. [RequireComponent(typeof(Camera))]
    2.  
    3. public class FooCamera : MonoBehaviour
    4. {
    5.  
    6. }
    Code (CSharp):
    1. [CustomEditor(typeof(FooCamera))]
    2. public class FooCameraInspector : Editor
    3. {
    4.     FooCamera self;
    5.     public void OnEnable()
    6.     {
    7.         self = serializedObject.targetObject as FooCamera;
    8.         self.GetComponent<Camera>().hideFlags |= HideFlags.HideInInspector;
    9.     }
    10.  
    11.     public void OnDisable()
    12.     {
    13.         self.GetComponent<Camera>().hideFlags &= ~HideFlags.HideInInspector;
    14.     }
    15. }
    Now before you ask, yes, I have tried with and without
    OnInspectorGUI. It's the same result.
    So now that this is easy to reproduce I look forward to seeing it solved because from what I can gather with Google searches, this issue has been around for a long time and is still not solved. It causes people a lot of problems because there is no fix to apply or use to circumvent it.


    I am using Windows 10, with Unity 2020.1.0f1 with no preview packages (although it didn't make a difference whether I had any installed or not. I tried both). Exact steps to reproduce:
    1. Make a new empty project with Unity 2020.1.0f1
    2. Setup the two files as shown above. A component and an inspector in the Editor folder.
    3. Make a new empty game object in your scene.
    4. Add the new component to the empty gameobject.
    5. Try and disable the gameobject or expand its header.
    6. The first click will do nothing, the subsequent clicks will trigger the warning in the console.
    So just to reiterate; The code above hides the camera but it also makes its impossible to interact with my own component after the fact.