Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by ghostravenstorm · Oct 30, 2016 at 04:03 AM · sorting layersmesh renderersprite renderer

Do Mesh Renderers for textures on quads have a sorting layer for 2D games?

I have a parallax background made of several layers that parallax at different rates. The textures that contain transparency are somehow rendering over my sprite renderer and I don't know how to change the priority.

alt text

unknown.png (113.0 kB)
Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Oct 30, 2016 at 08:26 AM 0
Share

The order with which objects are drawn to the screen is a combination of their sorting layer and order, render queue, and distance from the camera (i e. z coordinate). Opaque objects are drawn first and sorted front-to-back and then transparent objects are drawn but sorted back-to-front. Balancing these variables to get the correct layering can be tricky when you have a complex scene. What shader and material properties are you using? Is your character actually closer to the camera than the background (it appears so from the screenshot).

avatar image ghostravenstorm tanoshimi · Oct 30, 2016 at 09:02 AM 0
Share

The Z coordinate of the background is behind the character. Background: 1, Character: 0, and Camera: -10. I am using custom sorting layers on the sprite renderer component because I have things like lights that must be in front of the character and climbable objects that must be behind the character. I can't seem to find any of the sorting layers on the mesh renderer for quads which is what I'm using to display the background.

avatar image ghostravenstorm tanoshimi · Oct 30, 2016 at 09:05 AM 0
Share

I'm using an unlit texture shader for the sky layer, and an unlit transparent shader for the shubbery.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by ghostravenstorm · Oct 30, 2016 at 09:37 AM

To answer my own question, yes, they do.

After digging around in the API I found a hidden variable for the Mesh Renderer. sortLayerName. Well, not really hidden since its documented, but its not listed in the component interface in the editor. Bit of an oversight when you have sprites with their own render priority on top of a quad that automatically assumes the default layer.

     public string sortingLayer;
     
     void Awake(){
         for(int i = 0; i < SortingLayer.layers.Length; i++){
             if(SortingLayer.layers[i].name == sortingLayer)
                 this.GetComponent<Renderer>().sortingLayerName = sortingLayer;
         }
     }

This fixes the issue at runtime, but what about in editor? Is there a way to set that variable on change in the editor when working on a scene?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

58 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Sorting Layers in a 3D Environment 1 Answer

Drawing sprites in front of meshes 1 Answer

How do I set the rendering order of objects with the same sorting layer and order? 1 Answer

Sprites rendered in the wrong order 1 Answer

loading assets 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges