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
1
Question by IntDev · Mar 11, 2014 at 02:37 PM · 2dspriterenderorder

Grouping sprites 2d order

I have two gameobjects with some sprites that depicts two characters.

The problem is, when one pass through other they blend, ie, the head of one stays in front of the body of the other. The hand of one stays in front of the body of the other. THe expected result is the whole body (all sprites) stays in font or in back of the other character. I dont know how to achieve that.

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

Answer by TrevorP · Mar 11, 2014 at 02:42 PM

When you instantiate your player objects you'll need to set their transform.position.z values. If they both have the same z values for the sprites and are on the same sorting layer they will get mixed up like you describe.

I had a similar issue where I had a Player object with head, body, and legs sprites as children of the Player object. When two players ran into each other they would melt together. Changing the Player object's z value (and by relativity, the child sprites) it fixed the issue

Comment
Add comment · Show 3 · 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 IntDev · Mar 11, 2014 at 02:51 PM 0
Share

the problem is "Order in Layer" property... even if i change z, using Order override it.

avatar image IntDev · Mar 11, 2014 at 02:53 PM 0
Share

So it seems I will have to set them all to zero and control z-order only by z transform :(

avatar image TrevorP · Mar 11, 2014 at 04:53 PM 0
Share

Oh, yeah. I should have mentioned my players are on the same sorting layer and the Order in Layer is zero'd out for everything. I'm not sure what the best way to order cloned objects / objects with the same ordering.

One option is to increment the Order when you instantiate a player object

avatar image
0

Answer by BrunoMikoski · Mar 11, 2014 at 03:08 PM

Do you are using Unity 3D?

If the answer is yes you need to use the layer orders: https://www.youtube.com/watch?v=K-vin66NsiQ

If you are using just sprites, you need to organize that using the Z index.

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 ImpishMario · Mar 11, 2014 at 03:07 PM

Assuming that you make 2D game, it's enough to set proper sorting layer order for your game objects containing Sprite Renderers ("z" position is irrelevant in 2D in terms of sprite rendering). Try this: for character A, set sorting layer in each Sprite Renderer component (child and parent) to 10 and for character B, set them for e.g. 20. Whole character B should be visible "in front" of character A then.

Hope this helps.

Comment
Add comment · Show 2 · 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 TrevorP · Mar 11, 2014 at 04:49 PM 0
Share

This isn't entirely true. The Z position becomes relevant if the sprites are on the same sorting layer.

avatar image bugshake · May 10, 2016 at 02:48 PM 0
Share

This doesn't work if the sorting layer is not defined, which makes it unusable for a dynamic approach.

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

25 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

Related Questions

2D sprite rotation with velocity and interpolation 1 Answer

Sprite disappears in front of background 1 Answer

Scissor tool with 2d sprite 0 Answers

SpriteManager 2 1 Answer

How to alternate images in 2d unity 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