Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
1
Question by pamelacook · May 27, 2018 at 04:29 PM · videorendertexturerender texture

How Do I Reset a Render Texture to Black when I stop a video from playing?

When I first play my applications my render textures appear as black. When I play a video and pause it the video stops playing and pauses as expected. When I do VideoPlayer.Stop() the video stops but the video player still shows where the video stopped.

I would like the video player to show either black or preferably another color to show there is a video screen. The render texture material is Sprites/Default as suggested from this video that I used to create my video players. The steps used to use render textures for videos is about halfway through the video.

I don't know where to go from here. There has been very little I have been able to find on using and scripting for render textures for videos in Unity.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
7

Answer by tillmonkthered · Jul 31, 2018 at 03:46 PM

I was having a similar problem. I found that if you can get a reference to the RenderTexture, you can call its Release() method, and this seems to do the required reset.

https://docs.unity3d.com/ScriptReference/RenderTexture.Release.html

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pamelacook · Jun 19, 2019 at 08:25 PM 1
Share

It's been a while since I took a look at this. I tried Release() as below where I selected the render texture I wanted to reset. I also tried DiscardContents(). Neither of them cleared out the render texture.

 public void ClearOutRenderTexture(RenderTexture renderTexture)
     {
         renderTexture.Release();
     }



avatar image BlinksTale · May 20 at 07:19 AM 0
Share

I was seeing a flicker in editor of the old contents every time I restarted a video - this is a perfect solution to that. Thank you!

avatar image
3

Answer by pamelacook · Jun 19, 2019 at 10:42 PM

It took me a while but I was able to find a solution in the Unity forum. I decided to make the background transparent.

 public void ClearOutRenderTexture(RenderTexture renderTexture)
     {
         RenderTexture rt = RenderTexture.active;
         RenderTexture.active = renderTexture;
         GL.Clear(true, true, Color.clear);
         RenderTexture.active = rt;
     }


Here's the link where I found the solution.

Clear Renter Texture Link

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

Answer by Fenikkel · Jan 28, 2021 at 09:19 AM

Release it works for me:

 m_VideoPlayer.targetTexture.Release();

But in the documentation says that use it only "when you are finished using them"

So maybe make it transparent it's the best solution:

 RenderTexture rt = RenderTexture.active;
 RenderTexture.active = m_VideoPlayer.targetTexture;
 GL.Clear(true, true, Color.clear);
 RenderTexture.active = rt;




Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Rs · Mar 28 at 10:49 AM

The answers that suggest to reset the texture to black using GL.Clear are perfectly valid. But sometimes it can be sufficient to just set the clip to a black video, so here's the alternative:

  • make a black, 1 or 2 seconds black video
    Which can be created with ffmpeg
    ffmpeg -loop 1 -i black.png -c:v libx264 -t 2 -pix_fmt yuv420p blackvideo.mp4

  • Put blackvideo.mp4 in a Resources folder

  • Create a 'Clear' extension method for VideoPlayer

    using UnityEngine; using UnityEngine.Video;

    public static class ExtensionMethods {

       private static VideoClip _blackVideoClip;
         private static VideoClip blackVideoClip { 
             get {
                 if(_blackVideoClip == null)
                 {
                     _blackVideoClip = Resources.Load<VideoClip>("blackvideo");
                 }
                 return _blackVideoClip;
             }
         }
     
         public static void Clear(this VideoPlayer _vp)
         {
             _vp.clip = blackVideoClip;
         }
     
     }
    
    
  • Use the extension method

       myVideoPlayer.Clear();
    
    
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

148 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Combining a projected texture with a render texture 0 Answers

VideoPlayer HDR (Rec.2020) support 0 Answers

FPS y-axis mouse look not working on a render texture 0 Answers

PostProcess Outline Shader GVR alignment 0 Answers

Best solution for an interactive movie (Canvas/3D Plane/...) 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges