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. Dismiss Notice

Can "Sorting Group" be accessed from script?

Discussion in '2D' started by David-Flook, Apr 3, 2017.

  1. David-Flook

    David-Flook

    Joined:
    Nov 13, 2013
    Posts:
    47
    So you can enable/disable or change the layer during runtime?
     
  2. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    729
    PersianKiller and Imvincible13 like this.
  3. David-Flook

    David-Flook

    Joined:
    Nov 13, 2013
    Posts:
    47
    No sorry, I'm referring to the new component in Unity 5.6 called "Sorting Group".
     
    Imvincible13 likes this.
  4. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    729
    blisz and Imvincible13 like this.
  5. David-Flook

    David-Flook

    Joined:
    Nov 13, 2013
    Posts:
    47
    I was thinking that too but it seems "SortingGroup" isn't a type or maybe I'm missing a namespace or something.
     
    Imvincible13 likes this.
  6. flashframe

    flashframe

    Joined:
    Feb 10, 2015
    Posts:
    729
    UnityEngine.Rendering
     
  7. sam_nau

    sam_nau

    Joined:
    Oct 26, 2013
    Posts:
    9
    These are the kinds of things that should be explicitly called out in the Unity API docs. I know it lists its inheritance, but a simple example on how to call this component would be extremely helpful.
     
    Kokowolo, diesoftgames, blisz and 5 others like this.
  8. tiddlesworthgames

    tiddlesworthgames

    Joined:
    Dec 8, 2017
    Posts:
    3
    Thank you, ive been looking for where that was. Thought it might be in their documentation but it didnt specifically mention.
     
    Imvincible13 likes this.
  9. LiterallyJeff

    LiterallyJeff

    Joined:
    Jan 21, 2015
    Posts:
    2,802
    Just for future reference since this is an old post being unearthed:

    You can indeed find the namespace in the doc header:
    https://docs.unity3d.com/ScriptReference/Rendering.SortingGroup.html
    Screen Shot 2019-05-06 at 5.44.17 PM.png and while it's not always a great idea to rely on your IDE for everything, it's in your best interest to be using one that can tell you the namespace you're missing.
     
  10. mhmad2212

    mhmad2212

    Joined:
    Sep 12, 2019
    Posts:
    5
    correct answer:
    Just look at the reference code.
    To use SortingGroup, you must add UnityEngine.Rendering name space.
    Code (CSharp):
    1. first:
    2. using UnityEngine.Rendering;
    3. Then:
    4. GetComponent<SortingGroup>().sortingOrder = 1;

    Good luck
     
    Oranger97, ar253336 and Imvincible13 like this.
  11. Imvincible13

    Imvincible13

    Joined:
    Aug 28, 2020
    Posts:
    2
    Thanks this post was really useful!