Search Unity

ShadowCaster2d - m_ApplyToSortingLayers

Discussion in 'Universal Render Pipeline' started by urieljavieraiz, Sep 23, 2020.

  1. urieljavieraiz

    urieljavieraiz

    Joined:
    Sep 23, 2020
    Posts:
    1
    Hello,

    Is posssible to add a public function or make public the property m_ApplyToSortingLayers to modify the sorting Layer pls???

    Thnks
     
  2. pescetellimarco

    pescetellimarco

    Joined:
    Jul 15, 2022
    Posts:
    1
    Hi, maybe is too late for you, but for other developer, you must use Reflection.Like this:


    Code (CSharp):
    1. FieldInfo layerField = typeof(ShadowCaster2D).GetField("m_ApplyToSortingLayers",
    2.                                                                  BindingFlags.NonPublic |
    3.                                                                  BindingFlags.Instance);
    4.  
    5. layerField.SetValue(shadowCaster2DComponent, new int[] { 1 });

    You must use first attribute of layerField.SetValue a ShadowCaster2D component, and for second/last attribute you must use an int array and put a layer number you want use in shadowcaster2D ( i use new int[] { 1 } ).

    But is much better if you see how int value there are in layerField like this :

    Code (CSharp):
    1. for (int i = 0; i < (layerField.GetValue(shadowComponent) as int[]).Length; i++) {
    2.             var obj = (layerField.GetValue(shadowComponent) as int[])[i];
    3.             Debug.Log(obj);
    4.         }
    And then put value int in layerField.SetValue();
     
    Last edited: Jul 15, 2022