Is it possible to have unique layers in every scene?

The Layers and Sorting Layers prevail throughout the project and I have a lot of folders and scenes in a massive project that I use for prototyping stuff. Is there a way to restrict the Layers and Sorting to particular scenes? Like an asset or setting that I don’t know of.

Ugh, yeah, I feel your pain. AFAIK the answer is “no.”

It’s even worse because Sorting Layers, IIRC, won’t port between projects, at least they didn’t last time I checked. IOW, if you have Sorting Layer foo in project A and then make a Sorting Layer foo in project B, then make scenes / prefabs using those sorting layers, they are NOT the same layer as Unity refers to them by some arbitrary integer hash.

I tend to control it by just making code explicitly drive things like Layer / SortingLayer… that code will generally port over if you move your prototype game “embryo” from one project to another.

My largest prototype Unity project (I have actually many of these for various purposes) is completely out of control with over 500 scenes.

9396590--1315061--Screen Shot 2023-10-08 at 11.05.50 AM.png

BUT!! I could stop at any point if I wanted to. :slight_smile: Er, no I can’t.

Would’ve been quite nice if they did make the option to have scene specific sorting layers/layers. I’ve had the same issue while importing project assets. Perhaps it’s to preserve the integrity of bigger projects, but it’s a bane for prototyping.

500 scenes, eh? There are entire Netflix series with fewer than that… Competing with One Piece, are we?

1 Like

The layers are saved as integers from 0 to 31 so in theory you could have a script that just changes the names of the layers when opening a scene. The names are saved in ProjectSettings/TagManager.asset and there might be some editor api that can change them. Then you must have a script in each scene with the list of names specific to that scene that then applies it (also in edit mode). This obviously will break if you load scenes additively that have different meanings for the layers. If you set layers in prefabs you also could not share them between scenes with different layer definitions if the definitions were not compatible. This is probably why Unity has not bothered to add this feature

Yes, this is true for Layers. AFAIK you don’t even technically NEED to define a layer to use it in code.

BUT… OP also called out Sorting Layers, and those are the tricky ones. Here’s why:

The human-readable name is NOT used to identify the Sorting Layer.

Instead a capriciously-assigned value is generated, different (apparently) between every project.

9398279--1315496--Screen Shot 2023-10-09 at 9.34.16 AM.png

Unfortunately this seemingly-random value is what gets serialized to your scenes / prefabs, which is a data design failure for (AFAICT) no actual benefit to anything:

9398279--1315499--Screen Shot 2023-10-09 at 9.42.28 AM.png

The m_SortingLayer: appears to be an index into the list, but it is apparently ignored on the tests I did.

If someone knows how to safely pass prefabs from one project to another while preserving the SortingLayer regardless of ID, I’d love to hear it. We just manually go through check them all anytime we import a “foreign” prefab.

You bring up an excellent point about Sorting Layers being hand-editable via the TagManager.asset text file, and that could certainly be a way to ensure consistency across multiple projects.

But you would have to have the foresight to pre-program all your desired SortingLayers in and copy them from project to project, all before you made ANY asset using them. That is FAR outside the bounds of what I would consider normal reasonable use of the feature.