How do I instantiate movieTextures

I’m attempting to use a movie texture on multiple instantiated gameObjects, but they all seem to be pointing to one instance of the texture. This means they are all linked to one playback of the texture, where I need them to be independent.

I read in another thread that I need to instantiate the movieTexture, but that doesn’t seem to be working. Where am I going wrong?

Fixed **

	private MovieTexture movie;

	public MovieTexture moviePrefab;
	
	void Start () 
	{

		MovieTexture clone = new MovieTexture();
		clone = Instantiate (moviePrefab);
            clone.name = Random.Range(0, 10000).ToString();

		GetComponent<Renderer>().material.SetTexture ("_MainTex", clone);
		movie = ((MovieTexture)GetComponent<Renderer>().material.mainTexture);
		movie.loop = false;
		movie.Stop();
		movie.Play ();

}

Problem solved… seems you also need to give the instantiated movie a unique name. Fixed above.

Next problem… This works just fine when using the standard shader, but when I use a custom shader (below) the movieTexture will not play. It should be noted that before being given unique names the movieTexture would in fact play just fine with this shader.

Shader "Dvornik/Distort" {
Properties {
 _Refraction ("Refraction", Range (0.00, 100.0)) = 1.0
 _DistortTex ("Base (RGB)", 2D) = "white" {}
}

SubShader {
 
 Tags { "RenderType"="Transparent" "Queue"="Overlay" }
 LOD 100
 
 GrabPass
 {
  
 }
 
CGPROGRAM
#pragma surface surf NoLighting
#pragma vertex vert

fixed4 LightingNoLighting(SurfaceOutput s, fixed3 lightDir, fixed atten){
        fixed4 c;
        c.rgb = s.Albedo;
        c.a = s.Alpha;
        return c;
  }

sampler2D _GrabTexture : register(s0);
sampler2D _DistortTex : register(s2);
float _Refraction;

float4 _GrabTexture_TexelSize;

struct Input {
 float2 uv_DistortTex;
 float3 color;
 float3 worldRefl;
 float4 screenPos;
 INTERNAL_DATA
};

void vert (inout appdata_full v, out Input o) {
  UNITY_INITIALIZE_OUTPUT(Input,o);
  o.color = v.color;
}

void surf (Input IN, inout SurfaceOutput o) 
{
    float4 distort = tex2D(_DistortTex, IN.uv_DistortTex) * IN.color.r;
    float2 offset = distort.rgb * _Refraction * _GrabTexture_TexelSize.xy;
    
    // project the coordinates to be within 0 and 1
    IN.screenPos.xy = IN.screenPos.xy / IN.screenPos.w;
    
    // check if _GrabTexture texels are inverted on the y-axis
    if (_GrabTexture_TexelSize.y < 0)
        IN.screenPos.y = 1-IN.screenPos.y;
        
    IN.screenPos.xy = offset * IN.screenPos.z + IN.screenPos.xy;

    float4 refrColor = tex2D(_GrabTexture, IN.screenPos.xy); //tex2Dproj(_GrabTexture, IN.screenPos);
    o.Alpha = distort.a;
    o.Emission = refrColor.rgb;
   
}
ENDCG
}
}

Shader taken from this page.