Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feature Request [HideInInspector] Functionality for Methods

Discussion in 'Editor & General Support' started by unity_vhwR5LxKQZuFcg, Feb 23, 2022.

  1. unity_vhwR5LxKQZuFcg

    unity_vhwR5LxKQZuFcg

    Joined:
    Oct 16, 2018
    Posts:
    2
    Ran into an issue recently where a public method that needs to be public (it is called externally by another package that does not care about implementation details) was being used incorrectly in UnityEvent properties (calling abstract class's Set instead of specific implementation's SetState which provides additional functionality) and I was asked if it was possible to hide Set from the dropdown.

    The only way to do this is to mark the base method as [Obsolete] due to how Unity populates the dropdown for method references. But this would hide Set in the dropdown for all implementation subclasses, some of which have a valid reason to call Set via a reference set in the inspector.

    Creating a new Set method that hides the base implementation (the method was not virtual for a reason) and then marking that as [Obsolete] doesn't work, because the base class still has a non-obsolete version (implementing this feature probably wouldn't fix my specific use-case, as the new method and base method are still different methods as far as Reflection goes).

    Checking for the attribute should just be an additional check inside the UnityEventDrawer class where the check for Obsolete already occurs.

    unityeventdrawer.png
     
  2. fipsy

    fipsy

    Joined:
    Sep 3, 2016
    Posts:
    13
    Hey,
    a quick solution I came up with is to flag your method with the SpecialName Attribute like so:

    Code (CSharp):
    1. [SpecialName]
    2. public void MyHiddenMethod()
    3. {...}
    You can see in your screenshot of the UnityEventDrawer code that methods with IsSpecialName flag get excluded.

    However I have not tested this solution any further for side effects. Would be awesome if you could comment here in case you find problems with it.

    In general I would also appreciate an official dedicated attribute for hiding methods from the inspector

    Cheers