How to get Video to always Play on top

I can’t seem to view the video player I have in my scene, here are the settings,


I have the video play when you press the bowling ball, I can hear it playing, but I can’t see it. I’ve tried setting it to Camera near plane, far plane, render texture? But none work. The object is directly on the bowling ball. Here’s my script for reference

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class VideoPlayButton : MonoBehaviour
{
    public bool isPlaying;
    public GameObject movie;
    public AudioSource voice;
    private float movieLength, voiceLength;

    private void Start()
    {
     
        voice = this.GetComponent<AudioSource>();
        voiceLength = voice.clip.length;
    }
    public void PlayVideo()
    {
        movieLength = (float)movie.GetComponent<UnityEngine.Video.VideoPlayer>().length;
        if(!isPlaying)StartCoroutine(StartPlaying());
    }

    IEnumerator StartPlaying()
    {
        isPlaying = true;
        voice.Play();
        yield return new WaitForSeconds(voiceLength + .5f);
        movie.SetActive(true);
        yield return new WaitForSeconds(movieLength);
        movie.SetActive(false);
    }
}

Thanks in advance.

Edit: Forgot to mention, the video is in .mp4 format.

Bump

videoplayer.targetCamera = Camera.main?

I inserted this, but it still just plays the sound, no video.

Maybe this.

GetComponent<VideoPlayer>().renderMode = VideoRenderMode.CameraFarPlane;

I created a new project to see your problem and created this script I attached to the camera. I put a video named Test in my Resources/Videos folder.

using UnityEngine;
using UnityEngine.Video;

public class VideoLayer : MonoBehaviour
{
    GameObject videoplayer;
    void Start()
    {
        //create our video GameObject
        videoplayer = new GameObject();
        //name it
        videoplayer.name = "Video Player";
        //add our videoplayer component
        videoplayer.AddComponent<VideoPlayer>();
        //reference our component
        VideoPlayer vp = videoplayer.GetComponent<VideoPlayer>();
        //set camera to use
        vp.targetCamera = Camera.main;
        //set render mode
        vp.renderMode = VideoRenderMode.CameraFarPlane;
        //load video clip
        VideoClip clip = Resources.Load<VideoClip>("Videos/Test");
        //set video clip
        vp.clip = clip;
        //play video
        vp.Play();
    }
}

Hmm, I tried it, but it still doesn’t show. I can hear the audio, but no video. Here’s my adapted code.

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

public class VideoPlayButton : MonoBehaviour
{
    private bool isPlaying;
    public string videoName;
    public GameObject movie;
    public VideoClip clip;
    public AudioSource voice;
    public GameObject canvas;
    private float movieLength, voiceLength;

    private void Awake()
    {
        movie = new GameObject();
        movie.name = videoName;
        movie.AddComponent<VideoPlayer>();
        movie.GetComponent<VideoPlayer>().playOnAwake = false;
        movie.GetComponent<VideoPlayer>().targetCamera = Camera.main;
        movie.GetComponent<VideoPlayer>().renderMode = VideoRenderMode.CameraFarPlane;
        movie.GetComponent<VideoPlayer>().clip = clip;
        canvas = FindObjectOfType<Canvas>().gameObject;
        voice = this.GetComponent<AudioSource>();
        voiceLength = voice.clip.length;
        movie.GetComponent<UnityEngine.Video.VideoPlayer>().targetCamera = Camera.main;
    }
    public void PlayVideo()
    {
        movieLength = (float)movie.GetComponent<UnityEngine.Video.VideoPlayer>().length;
        if(!isPlaying)StartCoroutine(StartPlaying());
    }

    IEnumerator StartPlaying()
    {
        isPlaying = true;
        yield return new WaitForSeconds(.2f);
        movie.GetComponent<VideoPlayer>().Play();
        yield return new WaitForSeconds(movieLength);
        isPlaying = false;
    }
}

Can’t really help you beyond that. Start a new project and follow my instructions then you can see it work. Up to you to figure out how to adapt it.

Well, I can’t really start a new project lol, I already have a bit of time invested. At any rate, I got it kinda working by having it project to a render texture. But it only plays once, then reverts to being invisible again…

Well, if you, or someone else can help, this is what’s going on right now.

Ah so it is working but then the next video is supposed to play and never does? Maybe instead of coroutine try just using Update(). Maybe you can check if(currentLength >= movieLength) or store the time then do timer+=deltaTime then if(timer >= movieLength).

I don’t see why that would be the issue. I just tested it out with the same results. It plays once just fine. For some reason, the second time is either invisible, or sometimes doesn’t play at all…

Are you just trying to loop the same video? movie.GetComponent().isLooping = true?
Or if you are trying to find when the video ends I know creating a timer and manually counting will get you there.

If the videoplayer somehow just gets layered behind something after finishing a video then it is likely happening from somewhere else in your project.

I want it to start from the beginning when the video is played a second time. I just finally got it working, on near camera plane, but I can’t get it to play in the TV screen.

Here’s my current code, really not much different from before but lol

 using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;

public class VideoPlayButton : MonoBehaviour
{
    private float timer;
    private bool isPlaying;
    public string videoName;
    public GameObject movie, tvScreen;
    public VideoClip clip;
    public AudioSource voice;
    public GameObject canvas;
    private float movieLength, voiceLength;

    private void Awake()
    {
        canvas = FindObjectOfType<Canvas>().gameObject;
        voice = this.GetComponent<AudioSource>();
        voiceLength = voice.clip.length;
        movie.GetComponent<UnityEngine.Video.VideoPlayer>().targetCamera = Camera.main;
    }
    public void PlayVideo()
    {
        movieLength = (float)movie.GetComponent<UnityEngine.Video.VideoPlayer>().length;
        if(!isPlaying)StartCoroutine(StartPlaying());
    }


    IEnumerator StartPlaying()
        {
            isPlaying = true;
            yield return new WaitForSeconds(.2f);
            tvScreen.SetActive(true);
            movie.GetComponent<VideoPlayer>().Play();
            yield return new WaitForSeconds(movieLength);
            tvScreen.SetActive(false);
            isPlaying = false;
        }
}

I really don’t understand what’s wrong, it works fine now on camera, but not on the material.