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);



imageTexture.mainTexture = tmpTexture.texture;

tmpTexture.timeStamp = Time.timeSinceLevelLoad - playTime;


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



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.