Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Video Player Prefab: Render Texture not updating

Discussion in 'Virtual Production' started by AR_Tehcnoplus, Apr 14, 2022.

  1. AR_Tehcnoplus

    AR_Tehcnoplus

    Joined:
    Jan 17, 2022
    Posts:
    15
    Hi

    I have created a video player prefab, assigned to a list of different game objects. Each game object has a different video attached to it. So, when I am tracking an image I am enabling the video. The sound of the video is correct, but the Render texture is stack and displays a part of another video.

    The code that I have used is :

    Code (CSharp):
    1. public class VideoPrefabBehaviour : MonoBehaviour
    2. {
    3.  
    4.  
    5.     // Start is called before the first frame update
    6.     private VideoPlayer videoPlayer;
    7.     private VideoClip videoClip;
    8.  
    9.     DefaultObserverEventHandler parentEventObserver;
    10.     private void Awake()
    11.     {
    12.        
    13.         videoPlayer = GetComponentInChildren<VideoPlayer>();
    14.         if (!videoPlayer)
    15.             Debug.LogError("NO video player component found");
    16.         videoClip = videoPlayer.clip;
    17.         parentEventObserver = transform.parent.GetComponent<DefaultObserverEventHandler>();
    18.         parentEventObserver.OnTargetFound.AddListener(OnTargetFound);
    19.     }
    20.  
    21.     private void OnTargetFound()
    22.     {
    23.        
    24.         videoPlayer.targetTexture.Release();
    25.         videoPlayer.clip = videoClip;
    26.         videoPlayer.Prepare();
    27.         videoPlayer.prepareCompleted += onPreperationComplete;
    28.      
    29.        
    30.     }
    31.  
    32.     void onPreperationComplete(VideoPlayer vPlayer)
    33.     {
    34.         videoPlayer.Play();
    35.     }
    36.  
    37.     void OnEnable()
    38.     {
    39.         videoPlayer.Pause();
    40.     }
    41.  
    42.  
    43. }
    44.