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

Child Sorting Layer Order in Layer

Discussion in '2D' started by HotairraccoonGames, Jan 1, 2015.

  1. HotairraccoonGames

    HotairraccoonGames

    Joined:
    Nov 29, 2014
    Posts:
    5
    Dear Forum,

    Is there an easy way to set the order layer of child gameObjects to the same as their parent gameObject, or - even better - to only use the parent order in layer and disregard the children?

    Thanks!
    Jon
     
  2. ctufaro

    ctufaro

    Joined:
    Dec 14, 2014
    Posts:
    9
    Hey Jon,

    Here's a possible snippet you could put in your Start()
    Code (CSharp):
    1.         foreach (var v in this.GetComponentsInChildren<T>())
    2.         {
    3.             v.renderer.sortingLayerName = this.renderer.sortingLayerName;
    4.         }
     
    Last edited: Jan 2, 2015