How to change the opacity of an overlay camera or render texture at run time?

I hope this question is OK to ask here!

What I’m trying to do: I have two cameras (one base, one overlay). I want to slowly fade the content of the overlay-camera on top of the base-camera.I tried adding a Render Texture to the overlay-camera and thought perhaps it has some attributes that I can access and change at run-time via code. But I can’t find any such attributes (for alpha-values/opacity).

Why: The reason I want this is because I have a 2D dialogue-system with portraits made up of many sprites animated with 2Danimation bones. I want the portraits to fade in/out when they speak and listen. But because the sprites overlap and fade it looks very odd as the opacities add in overlapping areas (see my gif below) when chaning their alpha-values:

rapidmellowgallinule

What I’ve attempted: So I thought if I have a overlay camera render the portraits only I can fade the whole camera’s view instead. I have a script (with a coroutine that could fade an attribute’s value) ready, but I don’t know if there’s a render texture attribute I can apply it to? Or if I can directly change camera opacity without a render texture? I tried changing the backgroundcolor (because that seemed to change camera-opacity on something here: RenderTexture Alpha Issue.. - #3 by cleonsucks ) with the below script just to see if it worked:

    public Camera cam;
    public RenderTexture rend;

    private void Start()
    {
        //cam.targetTexture = rend;
        var color = cam.backgroundColor;
        cam.clearFlags = CameraClearFlags.SolidColor;
        cam.backgroundColor = new Color(color.r, color.g, color.b, 0.5f);
    }

But it didn’t change the camera’s opacity (only the background which makes sense).
Is there anyone who knows how I can go about? Is what I’m trying to do even possible? I’ve googled around a lot but haven’t found anything. If it’s important I’m using URP and the 2D experimental renderer. My Unity version is 2020.3.21f1.

Thank you so much in advance!

PS: If the 2Danimation consisted of UI-sprites it would be a lot easier as you could just add “Canvas Group” to the parent gameobject of multiple UI-images and change the alpha-value in that, but 2DAnimation cannot be made into UI-elements (right now at least). Writing this down in case someone finds my thread in the future and is trying to do what I do (but with UI elements).

I think to get this outside of a Canvas context you may need to use a RenderTexture with an alpha-capable shader and second Camera to render what you want faded out to this RenderTexture, which you show on card in front of your non-fading scene.

Perhaps there is some handy dandy shader or post-processing effect you could bring to bear on it but I haven’t mucked with that stuff much yet.

Thanks so much for your suggestions! There seems to be no support for custom render textures (that use shaders) for the 2D Renderer right now unfortunately (but seems to be coming in teh future according to this thread: https://discussions.unity.com/t/765877 so that’s awesome news).

Hoping there’s a way to fix it in the version I’m using! If someone comes with a handy tips that could work I’ll try that, otherwise I may have to upgrade to a newer Unity version. Thanks :slight_smile: