Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 Faisalimran · Jul 02, 2018 at 12:46 PM · spriteunity 2dlayerstagssorting layers

How to merge Sorting Layers ?

I have two unity3d projects, both are using sprite renderers and sorting layers. Project 1 has Following Sorting Layers:

  1. Default

  2. Tile Map

  3. Items

  4. Animals

  5. UI

  6. Particles

Project 2 has Following Sorting Layers:

  1. Default

  2. Background

  3. Slots

  4. Chips

  5. Foreground

  6. Map

  7. UI


Project 1 is my main project. I need to merge these both projects. I created new layers in project 1 and then imported project 2 but sorting layers of project 2 are broken .Setting each layer again in project 2 is very difficult task and rework. How can i merge these two project without breaking any sorting layer or tags ?

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
2

Answer by Bunny83 · Jul 02, 2018 at 01:34 PM

You have to fix the layers before the import. The layer for each object is just the numeric value of the layer. Since your two projects have conflicting layers:

 //  layer   Project1     Project2
 //  ---------------------------------
 //    2   | Tile Map  |    Background
 //    3   | Items     |    Slots
 //    4   | Animals   |    Chips
 //    5   | UI        |    Foreground
 //    6   | Particles |    Map

When you just import project 2 into 1 then all what happens is that you basically renamed all the layers from project 2. Once merged you can't differentiate which object comes from which project.


What you have to do are those steps inside project 2 before you merge them:


Keep an eye on the target layers from project 1. If the layer names match, just move to the next layer. In your case only the first layer is the same. Since layer 2 should become "tilemap" you have to move your "background" layer to a free layer in both projects. So just use layer 8 for Background, layer 9 for Slots, layer 10 for Chips, layer 11 for Foreground etc. If "Tile Map" and "Map" should be considered the same you may want to move the objects from layer 6 to the now empty layer 2 in project 2. However if they are not the same, just use a new layer (12). Finally you probably want to move the objects from the UI layer 7 to the new UI layer 5.


Now here comes the major problem: There is no built-in way to change the layer of all objects on a certain layer. The layer may be set on scene objects (maybe in multiple scenes) or in prefabs stored in the project. Furthermore scripts may use already either hardcoded layers or LayerMasks which also need to be adjusted.


Though the main issue is the actual layer of the individual objects in scenes / prefabs. For this problem there are two approaches possible. First with the asset serialization mode set to "force text" you could create a script to iterate through all assets files in the project, search for the "m_Layer" field and apply the desired change. This should automatically cover all objects in all scenes as well as all prefabs.


The second way would do the changes with an editor script inside the editor. However that means you have to open, change and save each scene as well as iterating through all prefabs in the AssetDatabase. Also keep in mind that you have to search through the child objects as well.


Both ways may have the potential to fail or to corrupt your project if something goes wrong. Also keep in mind that the changes i've mentioned above may need to be carried out in a very specific order to not loose any information


Usually i perfer to apply changes inside Unity and go through the assetdatabase and Unity's serialization system. However i think in this case the manual route through the YAML text files may be faster. If you have a YAML parser you could make the process more safe / fail proof.


As far as i know there is no ready to use solution to this problem. Keep in mind that the layer names are just there for convenience. The only thing that matters is the layer index which is stored inside each object. Have a look at the example YAML file over here or at one of your own scene files. Find a "GameObject" and look for the "m_Layer" field.


Once you managed to move all objects to their new layers you should check your code, settings and LayerMasks where you may use layers and get your project2 working again with the new layers before you do the merge ^^

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 sj631 · Jun 23, 2021 at 07:20 AM 0
Share

thanks for help

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

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

Related Questions

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

is there any way to group sprites? - Unity2D, 1 Answer

Okay This is Officially WEIRD! Layers flipping out by themselves. HELP 0 Answers

hi this might be a dumb question but is there a way to make one sprite have multiple layers on different parts of it? 0 Answers

Unity2D Sorting Layers with Particle Systems 9 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