- Home /
URP how to change RenderFeatures properties/settings at runtime
Let's say I made custom Render Feature pass, with outlines, bloom, lut correction, etc. and I want the user/player to be able to change this settings in game to balance performance/quality, how can I do that?
I searched for methods in UnityEngine.Rendering.GraphicsSettings.renderPipelineAsset and googled a lot, but can't find anything useful.
Update: I'm trying to change any of these settings from code:
Update 2: I think I found what I was looking for, but why is it protected?
What's the reason, and how do I change something in some RenderFeature if that list is protected how am I suppose to use it "the right way"?
Are you trying to change the settings of a Volume profile?
Answer by curiouspers · Jun 09, 2020 at 03:11 PM
Turns out I can get access to this list using reflections like this:
var _rendererFeatures = _pipelineAssetCurrent.scriptableRenderer.GetType() .GetProperty("rendererFeatures", BindingFlags.NonPublic | BindingFlags.Instance) ?.GetValue(_pipelineAssetCurrent.scriptableRenderer, null) as List<ScriptableRendererFeature>;
If somebody will find this useful, make sure you're executing it only one time on Awake or Init, cause it's quite expensive.
Answer by Aviryx · Jun 03, 2020 at 06:31 PM
Render pipeline data is stored in the relevant asset file.
public class CustomRenderPipelineAsset : RenderPipelineAsset
{
public int someNumber;
}
But you are (presumably) using one of Unity's built-in solutions (URP/HDRP etc) so I'm not sure if you can access the data using the same methods as a custom pipeline.
public CustomRenderPipelineAsset customRenderPipelineAsset;
customRenderPipelineAsset.someNumber = 10;
You are most likely going to have to reference the asset for whatever pipeline you are using and grab the info that way.
You can see an example from the URP pipeline instance (https://github.com/Unity-Technologies/Graphics/blob/master/com.unity.render-pipelines.universal/Runtime/UniversalRenderPipeline.cs)
public class LightweightRenderPipeline
{
public LightweightRenderPipeline(LightweightRenderPipelineAsset asset)
{
}
}
public ExampleRenderPipelineAsset exampleRenderPipelineAsset;
exampleRenderPipelineAsset.USE_BLOOM = false;
Thanks, but I want to change not the RenderPipelineAsset properties, but rather it's RenderFeature's properties. Have you used the URP yourself? I updated the question with new findings.
Answer by JG-Denver · Jan 05, 2021 at 07:17 PM
I put a custom camera component on my camera and access it is the OnCameraSetup, you have access to the Camera object in the cameraData, so you can GetComponent with that. You then just update the custom camera component and change what you want in the pass.