[ad_1]
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It only takes a minute to sign up.
Anybody can ask a question
Anybody can answer
The best answers are voted up and rise to the top
Asked
Viewed
7k times
I have a Unity VideoPlayer where I use a render texture with an audio source to play the video. VideoPlayer.Stop
pauses the video and resets the time to 0. I want to reset the VideoPlayer back to its default after I stop the video player. I searched the Scripting API but I did not see anything obvious on how to do this. How do I do this?
\$\endgroup\$
2
I did a quick test on my machine, a quick solution to that would be to disable the VideoPlayer
component by calling myVideoPlayer.enabled = false
. This would stop rending the video, and render the rest of the object. If you want to re-use it you can re-enable it the same way.
You can edit the object’s material to change what the object looks like when the video is off.
\$\endgroup\$
3
I ended up going on to other projects, but found myself needing a solution to this issue again. It took me a few hours, but I was able to find a solution. I wrote a script to use the render texture I wanted to reset as input.
public void ClearOutRenderTexture(RenderTexture renderTexture)
{
RenderTexture rt = RenderTexture.active;
RenderTexture.active = renderTexture;
GL.Clear(true, true, Color.clear);
RenderTexture.active = rt;
}
I found the solution here in the Unity forum.
\$\endgroup\$
1
You can also clear out the content of the render texture. Keep a reference of your render texture and when you stop the player you can just
renderTexture.Release();
\$\endgroup\$
[ContextMenu(nameof(Clear))]
private void Clear()
{
if (rt != null)
{
var cmd = new CommandBuffer();
cmd.SetRenderTarget(rt);
cmd.ClearRenderTarget(true, true, Color.clear);
Graphics.ExecuteCommandBuffer(cmd);
cmd.Dispose();
}
}
\$\endgroup\$
You must log in to answer this question.
Not the answer you’re looking for? Browse other questions tagged .
lang-cs
[ad_2]