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

Question Change URP Renderer opaque layer mask via script

Discussion in 'Universal Render Pipeline' started by Namysoft, Jan 18, 2023.

  1. Namysoft

    Namysoft

    Joined:
    Sep 8, 2018
    Posts:
    10
    Hey guy,

    i want to change the opaque layer mask (screenshot) via script at runtime. Is it possible?

    My Code:
    Code (CSharp):
    1. RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
    2.  
    3. // Is it possible to change the layer mask?
    4. currentRenderPipeline .... SET_OPAQUE_LAYER_MASK(...);
     

    Attached Files:

  2. fleity

    fleity

    Joined:
    Oct 13, 2015
    Posts:
    289
    Yes you can, super easy, barely an inconvienence :p
    You just need to get a reference to the renderer / UniversalRendererData

    https://docs.unity3d.com/Packages/c...endering.Universal.UniversalRendererData.html

    there you have access to opaqueLayerMask and transparentLayerMask.

    I guess you can reference the renderer by assigning the asset from the project browser.
    Getting it by code alone from the currently active renderpipeline asset is a lot more work though (UniversalRenderPipelineAsset is a partial class which makes it extendable with an assembly reference, by doing that you can write your own functions to expose everything one could ever need).
     
  3. Namysoft

    Namysoft

    Joined:
    Sep 8, 2018
    Posts:
    10
    Ah okay, i have to reference the the data asset. I thought about it wrong way.

    Thanks!