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.

MeshRender Custom Inspector to edit Sorting Layer and Order

Discussion in '2D' started by lassade, Dec 2, 2016.

Thread Status:
Not open for further replies.
  1. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    127
    Hey guys I made this editor script that maybe helpful to some one. It adds two properties Sorting Layer and Sorting Order like in the Sprite compoment in the MeshRender inspector, this is useful if you are mixing 2D and 3D elements:

    TODO: Undo events

    Edit: Fixed Sorting Layer popup field.

    How it looks:
    MeshRenderEditorPreview.png
     

    Attached Files:

    Last edited: Dec 20, 2016
  2. _watcher_

    _watcher_

    Joined:
    Nov 7, 2014
    Posts:
    259
    Thank you! Your code helped me quite a bit!
     
  3. meebou

    meebou

    Joined:
    Mar 6, 2017
    Posts:
    46
    Hallelujah! You are awesome! :p Thank you!
     
  4. StuwuStudio

    StuwuStudio

    Joined:
    Feb 4, 2015
    Posts:
    165
    Oh, this is so helpful. Unity, take notes. Or at least tell me why this isn't a thing.
     
  5. swoy45

    swoy45

    Joined:
    Feb 1, 2018
    Posts:
    9
    Can't change materials on gameobjects with this script
     
  6. Jiaquarium

    Jiaquarium

    Joined:
    Mar 22, 2020
    Posts:
    41
    omg thank you!!!
     
  7. Selek-of-Vulcan

    Selek-of-Vulcan

    Joined:
    Sep 23, 2021
    Posts:
    70
    Thanks for this script! It works great.

    But it also reveals that even though I change the sorting layer in Code, the object's sorting layer doesn't change in the Inspector (as shown by your script). At runtime, if I change the value in the Editor (using your script), then it works correctly. But I'm baffled why I sometimes can't change the sorting layer in code -- even when debug messages say I've successfully changed it. Even more baffled because most of the time I *am* able to change its value in code; just in one case I can't.
     
  8. baoquoc860

    baoquoc860

    Joined:
    May 19, 2019
    Posts:
    3
    yeah thanks you. it help me save a lot of time
     
Thread Status:
Not open for further replies.