0:00:01.257,0:00:04.354 When making a 2D game detailed control over the 0:00:04.354,0:00:07.390 order in which items are rendered is a necessity. 0:00:08.180,0:00:10.180 One way of doing this is by using the 0:00:10.180,0:00:12.612 distance of the sprite from the camera. 0:00:13.440,0:00:15.440 Unity however provides a much more 0:00:15.440,0:00:17.177 powerful tool to do this, 0:00:17.567,0:00:19.094 sorting layers. 0:00:20.164,0:00:22.360 Sorting layers work with the sprite renderer 0:00:22.360,0:00:24.906 to determine the rendering order of sprites 0:00:24.906,0:00:27.298 regardless of their distance from the camera. 0:00:28.221,0:00:30.454 A sprite, or group of sprites, can be 0:00:30.454,0:00:32.454 assigned to a sorting layer. 0:00:32.982,0:00:35.765 These sorting layers are given a sorting order. 0:00:36.445,0:00:38.764 The items in the sorting layer are rendered 0:00:38.764,0:00:40.917 regardless of distance to the camera 0:00:40.917,0:00:42.917 based on this sorting order. 0:00:43.541,0:00:45.541 It is worthwhile noting that the sprites 0:00:45.541,0:00:48.572 must still be within the camera's frustum to be rendered. 0:00:49.486,0:00:51.946 For even more control, individual sprites 0:00:51.946,0:00:54.320 can be assigned an Order In Layer value 0:00:54.320,0:00:56.320 to define the rendering order of sprites 0:00:56.320,0:00:58.320 within a sorting layer. 0:00:59.193,0:01:01.028 Sorting layers can be found in the 0:01:01.028,0:01:03.028 Tags and Layers Settings panel. 0:01:03.970,0:01:06.191 The tags and layers settings panel can be 0:01:06.191,0:01:08.191 accessed in 2 ways. 0:01:08.815,0:01:10.815 From the sprite renderer component select 0:01:10.815,0:01:14.516 Sorting Layer - Add Sorting Layer. 0:01:15.320,0:01:17.347 From anywhere within the editor select 0:01:17.347,0:01:21.657 Edit - Project Settings - Tags And Layers. 0:01:22.875,0:01:24.875 With the tags and layers panel open 0:01:24.875,0:01:28.236 sorting layers can be added, deleted or rearranged. 0:01:29.150,0:01:30.984 There will always be a default layer 0:01:30.984,0:01:32.984 present in the sorting layers list. 0:01:33.885,0:01:36.852 The default layer cannot be renamed or removed 0:01:36.852,0:01:38.852 but it can be rearranged. 0:01:39.739,0:01:42.675 To add a new sorting layer click the plus button. 0:01:43.368,0:01:45.368 To rename a sorting layer select 0:01:45.368,0:01:47.936 the Name field and enter a new name. 0:01:48.697,0:01:51.239 To rearrange the order of a sorting layer 0:01:51.239,0:01:53.827 click and drag the layer in to a new position. 0:01:54.595,0:01:56.637 The sorting layers will render in 0:01:56.637,0:01:58.500 list order from top to bottom 0:01:58.500,0:02:00.500 with the first item drawn at the back 0:02:00.500,0:02:03.656 and the last item drawn on top as the last layer. 0:02:04.598,0:02:06.598 To assign a sprite to a sorting layer 0:02:06.598,0:02:08.598 select the sprite to be assigned 0:02:08.598,0:02:10.598 and in the sprite renderer component 0:02:10.598,0:02:12.820 use the Sorting Layer drop-down list 0:02:12.820,0:02:14.820 to choose a sorting layer. 0:02:15.541,0:02:17.541 For detailed control over multiple 0:02:17.541,0:02:19.541 sprites on the same sorting layer the 0:02:19.541,0:02:21.986 Order In Layer value can be set. 0:02:22.801,0:02:24.801 If, for example, multiple sprites 0:02:24.801,0:02:26.926 are used to create a character 0:02:26.926,0:02:28.926 all the sprites used to create that character 0:02:28.926,0:02:31.409 could be assigned to one sorting layer. 0:02:31.882,0:02:34.091 And then within that sorting layer 0:02:34.091,0:02:36.091 Order In Layer can be used to determine 0:02:36.091,0:02:39.312 the draw order of the sprites, creating the character. 0:02:40.599,0:02:42.599 It is worth noting that sorting layers 0:02:42.599,0:02:44.890 and Order In Layer are global and available 0:02:44.890,0:02:46.890 to all renderers in Unity. 0:02:47.514,0:02:49.998 Every renderer, including particle renderers 0:02:49.998,0:02:52.344 can specify a sorting layer and use a 0:02:52.344,0:02:55.348 Order In Layer value, even though only the sprite 0:02:55.348,0:02:58.645 renderer exposes these properties in the inspector. 0:02:59.394,0:03:01.658 To use sorting layers and Order In Layer with 0:03:01.658,0:03:03.961 other renderers simply use a script 0:03:03.961,0:03:05.961 to assign these values. 0:03:06.585,0:03:08.585 It is possible to set the sorting layer 0:03:08.585,0:03:12.761 by name or ID with renderer.sortingLayerName. 0:03:13.813,0:03:16.914 Or renderer.sortingLayerID. 0:03:17.718,0:03:20.310 To set the Order In Layer property use 0:03:20.310,0:03:22.658 renderer.sortingOrder. 0:03:23.432,0:03:26.136 For more information on renderers, tags and layers 0:03:26.136,0:03:29.399 including sorting layers and the Order In Layer 0:03:29.399,0:03:31.758 please see the information linked below.