Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Feedback Implement LayerMask.ToString

Discussion in 'Editor & General Support' started by Peter77, Aug 19, 2019.

  1. Peter77


    QA Jesus

    Jun 12, 2013
    Please implement/override the
    method and return meaningful information. In Unity 2018.4.4f1, calling the following code:
    Code (CSharp):
    1. LayerMask layer = LayerMask.NameToLayer("UI") | LayerMask.NameToLayer("Ignore Raycast");
    2. Debug.LogFormat("{0}", layer);
    Outputs to the Console window:
    It would be a lot more useful, if the output contains the layer names and the value. For example, the output could be like this instead:
    I'm aware that there is the
    property that represents the integer bitMask, but for debugging happiness, what I described above would make a lot of sense.
    Xarbrough and karl_jones like this.
  2. Xarbrough


    Dec 11, 2014
    I was about to open the same thread. ;)

    This would allow custom debug code to automatically log all properties of an object, for example:

    Code (CSharp):
    1. public static void DumpLog(object target)
    2. {
    3.     if (target == null)
    4.     {
    5.         Debug.Log("Null");
    6.         return;
    7.     }
    9.     Object unityObject = target as UnityEngine.Object;
    10.     System.Type type = target.GetType();
    12.     string message = unityObject != null ? unityObject.ToString() : type.Name;
    13.     message += " (Dump)\n";
    15.     FieldInfo[] fields = type.GetFields();
    16.     foreach (var field in fields)
    17.     {
    18.         string line = field.Name + ": " + field.GetValue(target).ToString();
    19.         message += line + "\n";
    20.     }
    22.     Debug.Log(message, unityObject);
    23. }
    There are a few more cases where code like this make development easier (showing properties in debug ui, etc), where we don't actually know the type and therefore cannot provide a custom string format. Instead, many of these quick development solutions rely on a reasonable default implementation of ToString.

    I hope Unity is able to implement ToString for all engine types in the future. It doesn't have to be perfect, but at least some kind of information.