Search Unity

Resolved ARPlaneManager: Enum PlaneDetectionMode 'Everything' option missing?

Discussion in 'AR' started by halinc, Sep 16, 2021.

  1. halinc

    halinc

    Joined:
    Feb 24, 2019
    Posts:
    32
    In the editor, there's the option to set plane detection mode to 'Everything' . Why is this option missing in the enum (https://docs.unity3d.com/Packages/c...ngine.XR.ARSubsystems.PlaneDetectionMode.html) ?

    I found a workaround in this thread https://forum.unity.com/threads/ar-...turn-off-planes-after-basic-placement.587725/ :

    Code (CSharp):
    1. /// <summary>
    2.     /// The not-documented enum mode to detect both horizontal and vertical planes
    3.     /// </summary>
    4.     private PlaneDetectionMode detectEverything = (PlaneDetectionMode)3;
    in the editor, this then shows as 'Mixed', so I guess it works (haven't properly tested it yet). Is this the way to go if you want to change the detection mode to 'Everything' at runtime?
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,142
    'Everything' is an Editor-only option for all Enum types with the [Flags] attribute.
    When an Enum type has [Flags] attribute, you can combine flags with C# Logical Or operator. So to make an 'Everything' from code for PlaneDetectionMode you have to write:
    PlaneDetectionMode.Horizontal | PlaneDetectionMode.Vertical


    (PlaneDetectionMode) 3
    "works" because "bitwise or" operation on numbers 1 and 2 will result in 3. Using such kind of code is asking for trouble because bit representation of enum values can change at any time resulting in a bug.
     
  3. halinc

    halinc

    Joined:
    Feb 24, 2019
    Posts:
    32
    thanks a lot for the detailed explanation! wasn't aware of the [Flags] attribute