Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Feedback No access to pipeline's RendererDataList

Discussion in 'Universal Render Pipeline' started by StaggartCreations, Nov 21, 2019.

  1. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,133
    I'm faced with an issue where I cannot set up a camera and assign it a specific ScriptableRenderPass through script. Currently, this is only possible through the Camera component UI. This regards a hidden camera controlled by a MonoBehaviour script, the user should not concern themselves with this camera.

    This camera requires a ScriptableRendererData asset to be assigned. The only method do so is to call UniversalAdditionalCameraData.SetRenderer(int index). This apparently assigns a ScriptableRenderer from the pipeline asset's m_RendererDataList. Though this list is marked as internal, so its impossible to query for the item I'm looking for, and its index. It seems the only way to use this function at the moment is through hard-coded indices.

    For an automated setup in the context of asset store packages, this is troublesome. Adding renderers to the pipeline through script is also not possible because of the restricted access. Or implement errors/warnings if the required ScriptableRendererData isn't assigned. Leaving the end user with no feedback as to why things aren't working. In addition, no functioning demo scene can be presented, which is required.

    Current workflow:
    - Add a custom ScriptableRendererData asset to the pipeline asset
    - Note the index it has in the list
    - Set value on public int field on MonoBehaviour script (used for SetRenderer)

    Paint point: requires user's knowledge of the required set up steps.

    Proposed solution:
    Allow access to m_RendererDataList so renderers can be added, or their respective list index can be retrieved. Which subsequently allows
    SetRenderer to be used in automation.
     
    PutridEx and ph_ like this.
  2. ph_

    ph_

    Joined:
    Sep 5, 2013
    Posts:
    232
    Had the same problem so I heavily agree with you; I ended up switching the SRP asset entirely (as it's the only thing that can be done in code ...).
     
  3. StaggartCreations

    StaggartCreations

    Joined:
    Feb 18, 2015
    Posts:
    2,133
    For anyone looking for a workaround, this appears to work:

    Code (CSharp):
    1.     ScriptableRendererData[] rendererDataList = (ScriptableRendererData[])typeof(UniversalRenderPipelineAsset).GetField("m_RendererDataList", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance).GetValue(UniversalRenderPipeline.asset);
    2.  
    3.     for (int i = 0; i < rendererDataList.Length; i++)
    4.     {
    5.         if (rendererDataList[i].name == "MyRenderer") camData.SetRenderer(i);
    6.     }
     
    PutridEx likes this.
  4. ProdiggaPA

    ProdiggaPA

    Joined:
    Nov 29, 2019
    Posts:
    11
    It is 2021 and this is still the workaround? Insane.
     
  5. tomicz

    tomicz

    Joined:
    Mar 16, 2015
    Posts:
    152
    It's 2022 and it's still a workaround :D