WebCamTexture, when are you updated?

I want to grab pixels from a webcam texture just as they arrive, but the pixels I receive using GetPixels32 (when didUpdateThisFrame is true) seem to be one frame behind when I compare to the original texture (displayed by GUI.DrawTexture). I’ve tried to grab the pixels on Update and LateUpdate.

When exactly is the texture updated?

UPDATE#1: When using OnPreCull, OnPreRender or OnPostRender then pixels and texture seem to be in sync. I still get some random time offsets, perhaps because I’m only grabbing pixels when didUpdateThisFrame is true =/

UPDATE#2: Using WatForEndOfFrame in a coroutine does not seem to fix the issue either.

Carl Emil

You want to grab them inside a coroutine that waits for the end of the frame:

   IEnumerator Grab() {
       yield return new WaitForEndOfFrame();
       //Grab pixels here
   }

Then when it changes

  StartCoroutine(Grab());

If you are going to be running your application on iOS or Android, use NatCam. It provides access to the raw pixel data of the camera, the native buffer (for use with native plugins), and will soon have video recording support. It’s worth a gaze and it’s blazing fast.