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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

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