Version: 2022.3
言語: 日本語
スプライトエディターデータプロバイダー API
スプライトの 9 スライス

Sorting Group

Sorting Groups allow you to group GameObjects with Sprite Renderers together, and control the order in which they render their Sprites. Unity renders Sprite Renderers in the same Sorting Group together, as if they are a single GameObject.

Sorting Group の設定

To place a GameObject into a Sorting Group, add the Sorting Group component to it. To do this, select the GameObject and go to Component > Rendering > Sorting Group, or select the Add Component button in the Inspector window of the GameObject.

Sorting Groupコンポーネントをゲームオブジェクトに追加すると、Unityは、そのコンポーネントがアタッチされているゲームオブジェクトのすべての子ゲームオブジェクトに同じ Sorting Group を適用します。


The ‘Sprite’ child objects belong to the empty parent GameObject’s Sorting Group.

Unityは、Sorting Group の設定を使用して、シーン内の他のレンダラーと Sorting Group 内でレンダラーをソートする方法を決定します。詳細は 2D ソートを参照してください。

Sorting Group 内のレンダラーをソートするために、Unity はソートグループ内のレンダラーの個々のソート設定を使用します。詳細は、Sorting Group 内のレンダラーのソートを参照してください。

Sorting Group プロパティ

Unity uses a Sorting Group’s Sorting Layer and Order in Layer values to determine its priority in the rendering queue among other Sorting Groups and GameObjects in the Scene.

Sorting Group コンポーネント
Sorting Group コンポーネント
プロパティ 機能
Sorting Layer このドロップダウンメニューからSorting Layerを選択または追加して、 レンダーキューでのSorting Groupの位置を決定します。 UnityはSorting Layerの設定でSorting Layerの順番を決定します。 Sorting Layersをリストに表示されている順にレンダリングします。 Sorting Layersの設定については、 タグとレイヤーを参照してください。
Order in Layer Set the render order of this Sorting Group within its Sorting Layer. Unity queues Renderers with lower values first in the render queue, so they appear before Renderers with higher values.
Sort At Root Enable this option to ignore all parent Sorting Groups if this Sorting Group is nested. This allows this Sorting Group to be sorted against other Renderers and Sorting Groups at the root level.

Sorting Layer を使ってスプライトをソートする方法の詳細は、2D ソートを参照してください。

Sorting Group 内のレンダラーのソート

Unity sorts all Renderers within the same Sorting Group by their individual Sorting Layer and Order in Layer Renderer properties. Unity does not consider each Renderer’s individual Distance to Camera property during this sorting process. Instead, it sets a Distance to Camera value for the whole Sorting Group (including all its child Renderers), based on the position of the root GameObject that contains the Sorting Group component.

Unity がシーンの他のレンダラーと Sorting Group 内で Sorting Group をソートする場合、Sorting Group 内部のソートはそのままです。

次の図は、ソート処理を示しています。

ソートグループ内部のソート処理
ソートグループ内部のソート処理

Unity treats all Renderers that belong to the same Sorting Group as a single layer, and sorts non-grouped Renderers based on their Sorting Layer and Order in Layer property settings.

パーティクルシステム

The Editor treats a Particle System that is a child of a Sorting Group as another Renderer within that Sorting Group, and sorts it internally among other Renderers based on its Sorting Layer and Order in Layer property settings.

When Unity sorts the Particle System with the other Renderers within the Sorting Group, it ignores the Particle System’s Sorting Fudge value.

ネストされた Sorting Group

ネストされた Sorting Group は、親ソートグループを持つ Sorting Group です。Unity は、ネストされた Sorting Group 内のレンダラーを最初に、親よりも先にソートします。Sorting Group within Sorting Renderers を参照してください。

ネストされた Sorting Group の内部ソート順を決定した後、ネストされた Sorting Group を親 Sorting Group 内の他のレンダラーや Sorting Group と一緒にソートします。ネストされた Sorting Group は、ネストされた Sorting Group を子として持つことができます。Unity は最も内側の子 Group をそれぞれの親よりも先にソートします。

以下の図は、ネストされた Sorting Group のソート処理の例を示しています。

ネストされた Sorting Group のソート処理
ネストされた Sorting Group のソート処理

Sort At Root

In certain situations, you may have a nested Sorting Group that is ordered based on the Scene Hierarchy. However, you may want this nested Sorting Group to be rendered separately from its parent Sorting Group without changing its position in the Scene Hierarchy.

You can enable this option to allow this Sorting Group to ignore its parent Sorting Groups, which allows this Sorting Group to be sorted against other Renderers and Sorting Groups globally without requiring the GameObject to be reparented to another Transform. All child Renderers and Sorting Groups (which have not ignored their parents) will be sorted under this Sorting Group.

Sorting Group の使用

The most common way to create a 2D multi-Sprite character is to arrange and parent multiple Sprite Renderers together in the Hierarchy window to form a character. You can use Sorting Groups to help manage this kind of complex multi-Sprite character.

In the example below, the Sprite Renderers belong to the same Sorting Layer, but with different Order in Layer values. Unity sorts the different parts of a character in the order that you want them to appear.

階層内にパーツを持つキャラクタープレハブ
階層内にパーツを持つキャラクタープレハブ

Sorting Group と Sorting Layers を設定した後、キャラクターをプレハブとして保存し、必要なだけクローンすることができます。

However, Prefab Sprites all have the same Sorting Layer and Order in Layer values and render to the same layers as other Prefabs, which can cause different parts of a Prefab character to intersect and layer incorrectly.

Unity はスプライトを同じレイヤーにレンダリングするため、2つのプレハブのスプライトが正しく交差しません
Unity はスプライトを同じレイヤーにレンダリングするため、2つのプレハブのスプライトが正しく交差しません

プレハブが独自のレンダリング順序を維持して正しく表示されるようにするには、各プレハブのルート GameObject に Sorting Group コンポーネントを加えます。編集したプレハブを保存します。すると、プレハブの現在および将来のすべてのインスタンスにも Sorting Group コンポーネントが含まれるようになります。

Each Prefab should have a Sorting Group component with the same Sorting Layer and Order in Layer property settings. This might cause Renderers in the Prefabs that are on the same Sorting Layer to render in inconsistent ways, because they have the same priority in the Render Queue.

To prevent this issue, give each Prefab’s Sorting Group component a unique Order in Layer value. Unity renders Sorting Groups with lower Order in Layer values first and those with higher values overlap the Sorting Groups that are lower. Refer to Tags and Layers for more information about editing and reordering Sorting Layers.

Each Prefab has a Sorting Group component with a unique Order in Layer value to ensure that Unity renders each character and their parts correctly.

SortingGroup

スプライトエディターデータプロバイダー API
スプライトの 9 スライス