Help optimizing code (WebCamTexture to Texture2D)

Hi guys,

I’m attempting to save a list of Texture2D images (it has to be Texture2D since Texture cannot be turned to a PNG and saved on disc) from a WebCamTexture:

Here’s the code I have:

tmpTexture = new TextureData();

tmpTexture.texture = new Texture2D(phoneCam.width, phoneCam.height);

tmpTexture.texture.SetPixels(phoneCam.GetPixels());

tmpTexture.texture.Apply();

imageTexture.mainTexture = tmpTexture.texture;

tmpTexture.timeStamp = Time.timeSinceLevelLoad - playTime;

phoneTextures.Add(tmpTexture);

Unfortunately, this doesn’t run as fast as I would have hoped. Any idea how I can optimize this?

Thanks,

Arseney.

P.S. TextureData class is made out of a float named timeStamp and a Texture2D named texture.

Don’t use new keyword, instead, reuse the created - allocated object.