Search Unity

  1. Are you interested in providing feedback directly to Unity teams? Sign up to become a member of Unity Pulse, our new product feedback and research community.
    Dismiss Notice

Help Wanted Graphics > Custom Axis - For Universal Render Pipleline

Discussion in '2020.1 Beta' started by Andromedog, Jan 13, 2020.

  1. Andromedog

    Andromedog

    Joined:
    Sep 26, 2017
    Posts:
    18
    Is it possible to access/edit the custom axis while using URP? If so, how?
     
  2. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    819
    You can access it globally through:
    If you want to set it on a per camera basis:
     
  3. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    45
    Is there any update on this? Removing the pipeline does not work any more.
     
  4. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,020
    This seems cumbersome, why not have URP show the transparency sort mode in the editor. Its easy enough to set in a script, but there should be consistency across all the renderers.
     
  5. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    819
    For Unity 2019.4 and URP 7.3.1, you can configure this in the 2D Renderer Data asset:

    upload_2020-7-1_14-31-41.png

    This should be the same for Unity 2020.1 and the compatible URP package. This can still be configured per Camera as well.

    Hopefully this will make it easier to configure this setting in URP!
     
    Henenenerik and Chris-Trueman like this.
  6. Chris-Trueman

    Chris-Trueman

    Joined:
    Oct 10, 2014
    Posts:
    1,020
    Ah cool, the last time I was playing around with URP and the 2D renderer I had to set it in a script. I thought that it should be easy to put in the asset. This is perfect, its directly in the asset thank you.
     
  7. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    45

    How do i use this and how in particular do i use this with a selected camera?

    Also can i use this with a mix of 2d and 3d? I want the 2d to be sorted but the 3d to work on the z.
     
  8. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    819
    The following is a global setting for all cameras.

    If you want to set it on a per camera basis, you can create a Monobehaviour that sets the sort mode and axis on Start:
    Technically, this is for sorting of transparent renderers, where SpriteRenderers and other 2D renderers generally use Materials with the Transparent queue for Alpha blending. 3D renderers generally use Materials with the Opaque queue and will not be sorted with the Transparency Sort Mode set but rather with the standard Z distance.
     
    bz_apps likes this.
  9. bz_apps

    bz_apps

    Joined:
    Aug 19, 2014
    Posts:
    45
    Hi, is there a way to get this to work in the editor view also? Its works as expected for the camera view which is great but its hard to design/lay things out in the editor.

    Thanks.
     
  10. ChuanXin

    ChuanXin

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    819
    You can try using this script and adding the TransparencySortModeHelper component to your Camera GameObject.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3.  
    4. [RequireComponent(typeof(Camera))]
    5. public class TransparencySortModeHelper : MonoBehaviour
    6. {
    7. }
    8.  
    9. #if UNITY_EDITOR
    10. [CustomEditor(typeof(TransparencySortModeHelper))]
    11. public class TransparencySortModeHelperEditor : Editor
    12. {
    13.     public override void OnInspectorGUI()
    14.     {
    15.         var camera = (target as TransparencySortModeHelper).GetComponent<Camera>();
    16.         EditorGUI.BeginChangeCheck();
    17.         var sortMode = (TransparencySortMode) EditorGUILayout.EnumPopup("Sort Mode", camera.transparencySortMode);
    18.         var sortAxis = EditorGUILayout.Vector3Field("Sort Axis", camera.transparencySortAxis);
    19.         if (EditorGUI.EndChangeCheck())
    20.         {
    21.             Undo.RecordObject(camera, "Change Sort");
    22.             camera.transparencySortMode = sortMode;
    23.             camera.transparencySortAxis = sortAxis;
    24.         }
    25.     }
    26. }
    27. #endif
    28.  
     
    ChiuanWei and bz_apps like this.
  11. Spiraseven

    Spiraseven

    Joined:
    May 2, 2014
    Posts:
    10
    Hi All, I have been trying to get transparency sort mode to work with URP in unity 2019.4.3f1 with the 2DRenderer. I set my settings to custom axis with y=1 in my 2d renderer settings and have added two 2d sprite objects to the scene. The camera is in orthographic mode if that makes a difference. They don't seem to swap when I drag them up and down over each other, one is always on top. Am I missing something here? The sprites are using the sprites/default shader.

    Update: Upon further investigation I am able to get this to work by using a script to update the transparency sort mode settings. But just changing it in the 2d renderer data settings doesn't seem to actually set the value. I can see in my source control that it is updating my 2DRenderer.asset but the GraphicsSettings.asset does not change, it keeps with whatever my script had set last, even after deleting the script.
     
    Last edited: Oct 13, 2020
    Stealcase and Hana094 like this.
  12. glacuesta

    glacuesta

    Joined:
    Nov 30, 2017
    Posts:
    6
    +1 for this, your update is the trick that saved the day!
     
    Hana094 likes this.
  13. Kaldrin

    Kaldrin

    Joined:
    Jul 10, 2018
    Posts:
    33
    Thank you I couldn't find this option, I didn't know you could change it via script !
     
  14. Stealcase

    Stealcase

    Joined:
    Feb 26, 2018
    Posts:
    2
    For those who are stuck on this, I think it's a bug in Unity. I made a report and will link here

    EDIT: Link to Issue in issue tracker: https://issuetracker.unity3d.com/is...en-setting-the-values-in-the-2d-renderer-data

    I think the Camera Orthographic Setting is putting the TransparencySortMode = Default and the TransparencySortAxis = 0,0,1, even if you specify it to be TransparencySortMode = CustomAxis and TransparencySortAxis = 0,1,0 in the 2DRender object.

    Spiraseven is right, this needs to be set in script.
    Simplest script I could make. Attach this to the Camera you want the Topdown Sorting

    Code (CSharp):
    1.     public class TransparencySortModeFixer : MonoBehaviour
    2.     {
    3.         private void Start()
    4.         {
    5.             cam = GetComponent<Camera>();
    6.             Debug.Log("TRANSPARENCY SORTING");
    7.             Debug.Log("Current Sort Mode:" + cam.transparencySortMode);
    8.             Debug.Log("Current Sort Axis:" + cam.transparencySortAxis);
    9.             cam.transparencySortAxis = Vector3.up;
    10.             cam.transparencySortMode = TransparencySortMode.CustomAxis;
    11.             Debug.Log("New Sort Mode:" + cam.transparencySortMode);
    12.             Debug.Log("New Sort Axis:" + cam.transparencySortAxis);
    13.         }
    14.     }
    Note: this does NOT work in the editor, only play mode!
     
    Last edited: Jun 18, 2021
    mobyjames and Kaldrin like this.
  15. mobyjames

    mobyjames

    Joined:
    Mar 23, 2015
    Posts:
    1
    Thanks, this helped me a lot. You can add
    Code (CSharp):
    1. [ExecuteInEditMode]
    to the top of your class so it will work in editor. Still only works in game view.
     
    ChiuanWei likes this.
  16. HortenseDoodlin

    HortenseDoodlin

    Joined:
    Sep 29, 2020
    Posts:
    1
    If someone else needs help on this, im on 2020.3 and this works: remove the asset, change your custom axis, close unity, reopen unity, change the asset back.
     
    Rashkin likes this.
unityunity