title: Unity - Writing texture data to byte array yields empty array
body: <p>I'm having a problem at the point of creating a byte array from texture data. I have two functions, one that writes texture to a file (which is working) and one that writes texture data to an array that then gets processed into a string. I'm trying to test to see if it works with a debug 'Debug.Log("Local variable textureString is : " + textureString);' but it's empty. What do I have wrong? Just to give a clear sense of what I'm trying to accomplish in whole I've created a diagram to illustrate:</p>
  
  <p><a href="https://i.stack.imgur.com/Hq0dK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Hq0dK.png" alt="enter image description here"></a></p>
  
  <p>So I have 4 clients running an application that allows users to create a custom texture and then a 5th client running a different application that takes that texture info and uses it to instantiate a custom character based on the texture2d, string animal type, and string client id.</p>
  
  <pre><code>    public byte[] textureBytes;
      public string textureString;
      public string textureType;
  
      public void WriteTextureToBytes()
      {
          SaveColoringBookTexturePNG();
  
          StartCoroutine(DoWriteTextureToBytes());
          Debug.Log("WriteTextureToBytes Button Pressed.");
      }
  
      IEnumerator DoWriteTextureToBytes()
      {
          yield return new WaitForEndOfFrame();
          RenderTexture tmp = RenderTexture.active;
          RenderTexture.active = BackLayerController.RenderTexture;
  
          TmpTexture2D.ReadPixels(new Rect(0, 0, RenderTextureSize.x, RenderTextureSize.y), 0, 0, false);
  
          textureBytes = TmpTexture2D.GetRawTextureData();
          textureString = Encoding.UTF8.GetString(textureBytes);
          textureType = PageConfig.UniqueId;
  
          player = GameObject.FindGameObjectWithTag("Player");
          player.GetComponent&lt;PlayerController&gt;().AnimalTex = textureString;
          player.GetComponent&lt;PlayerController&gt;().AnimalType = textureType;
  
          Debug.Log("Local variable textureType is : " + textureType);
          Debug.Log("Local variable textureString is : " + textureString);
          Debug.Log("PlayerController AnimalType is : " + player.GetComponent&lt;PlayerController&gt;().AnimalType);
          Debug.Log("PlayerController AnimalTex is : " + player.GetComponent&lt;PlayerController&gt;().AnimalTex);
      }
  
      public void SaveColoringBookTexturePNG()
      {
          StartCoroutine(DoSaveColoringBookTexturePNG());
      }
  
      IEnumerator DoSaveColoringBookTexturePNG()
      {
          yield return new WaitForEndOfFrame();
          RenderTexture tmp = RenderTexture.active;
          RenderTexture.active = BackLayerController.RenderTexture;
  
          TmpTexture2D.ReadPixels(new Rect(0, 0, RenderTextureSize.x, RenderTextureSize.y), 0, 0, false);
  
          File.WriteAllBytes(SaveFilePath, TmpTexture2D.EncodeToPNG());
  
          Debug.Log("File Saved to: " + SaveFilePath);
      }
  </code></pre>