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 Turkeybag · Sep 29, 2014 at 12:16 PM · spritelayerscharactersoverlapping

Multi sprite characters order themselves as a whole rather than as individual parts

So I have a bunch of zombies that are made out of several sprites so that it's easy to animate and change parts around. The zombies themselves layer fine but when multiple zombies are near each other the individual parts of each overlap and this causes layering problems.

alt text

The only solution I can think of it to change the order in layer of every individual part of a zombie each time one spawns but that seems really inefficient. Is it possible to have the zombies order themselves instead of each individual part? So one zombie will be completely on top of another rather than only half of him being on top.

layer problem.png (176.0 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

1 Reply

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

Answer by Kiwasi · Sep 30, 2014 at 01:07 AM

Change the order of layer for each individual part for each zombie. Pseudo code as follows:

 static int zombieNumber;
 
 void Start (){
     zombieNumber ++;
     foreach (sprite in zombie){
         sprite.sortingOrder = sprite.sortingOrder + 100 * zombieNumber;
     }
 }

You can go as high as you want (almost) with sorting order. So there shouldn't be any problems with this approach.

Comment
Add comment · Show 5 · 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 Tepei · Sep 30, 2014 at 01:21 AM 0
Share

The maximum of sorting order is 36767..

avatar image Turkeybag · Sep 30, 2014 at 02:03 AM 0
Share

Shouldn't be a problem if a reset the counter once it hits 1000. This should work well! Quick question, is it cheaper to make a public variable for the sprite renderer of each part on the base and then drag in each sprite so I don't have to use getcomponent or should I just go with getcomponent?

avatar image Kiwasi · Sep 30, 2014 at 08:21 AM 0
Share

GetComponent is cheap enough if you use it once then store the reference.

I wouldn't worry about the cost of GetComponent until you start hitting frame rate issues.

avatar image Kiwasi · Sep 30, 2014 at 08:34 AM 0
Share

@Tepei $$anonymous$$y understanding was it was implemented as an int32, as opposed to an int16. Are you aware of any documentation that says otherwise? The default for C# appears to be an int32

I have no particular use for this information at the moment, but I like to have the correct details in case I need them.

avatar image MindGem · Aug 08, 2021 at 01:18 PM 0
Share

I tried this...in game mode it shows it works, they're at separate sorting layers but they still overlap?

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Is there a way to mask out a sprite layer 0 Answers

I need my GameObject to Spawn in front of my sprites 2 Answers

How to avoid having clones on the same order in layer clip? 0 Answers

Scissor tool with 2d sprite 0 Answers

2D Games in Unity3D? 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