Access to RenderObjects pass info from script?

Hello,

I have a UWP project that is using the “RenderObjects” render pass to draw an overlay grid on the scene with some feedback data. That works great so far.

However, I need to access this RenderObjects pass through code, in this case to set the override material from code. I can’t seem to figure out how to get to this through the api. Here’s the closest I’ve come:

            UniversalRenderPipelineAsset urpAsset = (UniversalRenderPipelineAsset)GraphicsSettings.renderPipelineAsset;
            ScriptableRenderer render = urpAsset.scriptableRenderer;

            ScriptableRendererData rendererData = render.???;


            List<ScriptableRendererFeature> rendererFeatures = rendererData.rendererFeatures;
            foreach (ScriptableRendererFeature feature in rendererFeatures)
            {
                RenderObjects objectPass = feature as RenderObjects;
                if (objectPass != null)
                {
                    // do something with objectPass
                    Debug.LogFormat("Override material is {0}", objectPass.settings.overrideMaterial.name );
                }
            }

Right now I’m working around this by just keeping a reference to the material somewhere else, but this is not idea for a few reasons – I would like to be able to enable/disable the overrideMaterial at runtime (right now I’m just setting and unsetting the layer for things so it’s always running the renderObjects pass even when it doesn’t need it, and also this modifies the .mat file in the scene which is just annoying.

Am I missing something to get access to the objectPass asset at runtime?

We’re using 2019.1.7f1 with LWRP 5.16.1, but I’ve also tried this with 2019.3.0b11 and UWP 7.1.5 since we’re considering upgrading and didn’t see any difference.

Thanks!
Joel

1 Like

Yep, you’re on the right track with that code snippet. Just use reflection to get the
m_RendererData field of the pipeline asset. Also keep in mind that you’ll need to change the override material on the pass itself not the feature. However, the feature has a reference to the pass called “renderObjectsPass”, which has a public setter for the override material. renderObjectsPass is marked internal so you’ll need to use reflection to get access to it as well.

1 Like

Hi, I took a different appoach to communicate with a renderpass.
you will need to create your own version of the renderobjects feature tho

I use a scriptable object, that holds the data i need.
in the renderfeature setting i have a slot to put this type of scriptableobject, and i pass this to the
ScriptableRenderPass.

in another script (monobehaviour) i reference the same asset, i can change any data i want.

hope this helps

2 Likes

For me it works for LWRP but in URP not working anymore :frowning:
Editor Works but Android Player dont

Hack with access to GraphicsSettings.renderPipelineAsset… through reflection works on URP :slight_smile:

Damn encapsulation:rage: