Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Mullberg · Aug 09, 2014 at 06:19 PM · 2dsortingsorting layers

Sorting sprites for render in 2D

Hello! I have a problem concerning rendering orders in 2D.

The problem can be seen in the following images: I have my character at a sorting layer above the tree-sprite. When the character walks behind the tree I need to swap the sorting layers somehow, anyone got any idea how to do this in unity?

alt text Image 1. No problem with sorting here, tree is one sorting layer behind my char

alt text Image 2. With the same sorting layers my char will look like he's climbing the tree but he should be behind (swap sortinglayers at runtime or something)

tree1.png (15.4 kB)
tree2.png (17.6 kB)
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by JustFun · Aug 09, 2014 at 08:35 PM

You don't need to change sorting layer. You need to swap your tree and character sprites sorting order. http://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html . Sprite with bigger sorting order will be rendered in front of sprite with smaller sorting order.

Comment
Add comment · Show 1 · 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
avatar image Mullberg · Aug 09, 2014 at 09:55 PM 0
Share

Thank you for this, this solved it for me. Setting sortingOrder statically for all the static objects with their position.y and updating it with position.y for the char as I keep rendering. Cheers!

avatar image
0

Answer by pooyafayyaz · Aug 09, 2014 at 07:59 PM

you can put the tree and the character in a same layer and change the z value when evere you want to have the character behind or not.

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
avatar image
0

Answer by ulysses 31 · Aug 10, 2014 at 09:52 AM

Also if you don't want your player to walk through the base of the tree, just add a small box collider at the base. This would mean that you can still walk behind the tree but not through the base of the tree.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Allow for sorting between different sorting layers 0 Answers

Soritng 2d objects 0 Answers

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

How to return tile based on heightmap efficiently? 0 Answers

CustomAxis sort not working between objects placed at different layers rendered by multiple cameras 0 Answers


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