How to achieve Video Fade In

Hello,

I try to implement video fade in on a video playing on a 3D surface. So I am setting the video player to Render Mode “Override Material” and the video plays just fine. Next I need to make it fade in, not just appear, so I thought - “easy, I will just override the target material’s alpha”, and tried to do that via the target renderer:
videoPlayer.targetMaterialRenderer: “Renderer which is targeted when Video.VideoPlayer.renderMode is set to Video.VideoTarget.MaterialOverride”, so exactly the case I have, and then:

Color col = videoPlayer.targetMaterialRenderer.material.color;
videoPlayer.targetMaterialRenderer.material.color = new Color(col.r, col.g, col.b, currentAlpha);

However, for my surprise targetMaterialRenderer is null.
I am not sure what I am missing, or is there another approach to this.
Any help or thoughts on this are much appreciated.

As the documentation on VideoPlayer.targetMaterialRenderer states:

Setting this to null causes the VideoPlayer to use the first Renderer of the current GameObject.

i.e. targetMaterialRenderer being null means it picks the renderer on the same game object, you’ll have to use GetComponent<Renderer>() instead.

Thank you, I missed that part somehow.
Changing the color of the MeshRenderer has no impact on the video transparency though - the video is shown and playing even with transparency set to zero. I mean is visible as if the alpha is completely disregarded, which is not the case on another object - Cube or so…

That depends on the shader your material is using. All the video player does is overriding the texture on the material.

What shader are you using? Some shaders give priority to the texture’s alpha channel and changing the main color won’t affect it.

It is right now with “Universal Render Pipeline/Lit”.
Which one would support the effect I need?

Make sure you have Surface Type set to Transparent, Blending Mode to Alpha and Alpha Clipping turned off.

Maybe try the URP Unlit, Sprite or Particle shaders.

1 Like

This worked perfectly fine, thank you very much!! :pray: