# Unity movie texture behaviour when hidden

I have a UI with a button and a panel. Clicking the button toggles the panel on and off :

GameObject.SetActive();


Now the panel element has a child which is a plane. This plane has the following components :

• mesh renderer
• videoPlay, a script I've written
• an audio source

The videoPlay script basically applies the MovieTexture to the plane's material, sets the plane's audioSource to the movie's audio clip, and starts audio and video.

public MovieTexture movie;

void Start() {
GetComponent<Renderer>().material.mainTexture = movie as MovieTexture;
GetComponent<AudioSource>().clip = movie.audioClip;
movie.Play();
GetComponent<AudioSource>().Play();
}


Now when at runtime I click the button (which hides the panel which is the plane's parent element), the audio and video stop as the plane disappears - which is expected behaviour.

When I reopen the panel though, the sound restarts right away but as if it were catching up for the time it was hidden (so it starts really fast and then comes back to regular speed) ; and the video is just frozen for - empirically and approximately - the same time the panel was hidden.

I've tried in the script - in Update() - messing with

if (!transform.parent.gameObject.activeSelf && movie.isPlaying)
{
movie.Pause();
GetComponent<AudioSource>().Pause();
}


for example, (and the same with Play() when it shows back up) but it doesn't seem to change anything.

• You need to pause before you de-activate the gameobject, not after. Apr 5, 2017 at 17:18
• Makes sense. I'll add a script to the button to make the toggle (right now I'm using unity itself), and play/pause appropriately. Apr 5, 2017 at 17:22
• If that solves the issue, make sure to add it as an answer and (after the required delay) mark it accepted - that will make it easier for other users with similar problems to find the solution. Apr 5, 2017 at 19:40