title: Kinect One & Unity - BodyIndexSource frame issue, drawing a "body-shadow" using the BodyIndexSource
body: <p>Alright so to explain myself better:</p>
  
  <p><strong>Goal:</strong> Making "shadow figures" in Unity
  <strong>Using:</strong> Kinect One, Unity, C#</p>
  
  <p>I am using the Windows Example source that they provide for Unity.</p>
  
  <hr>
  
  <p>Basically what I did is make a BodyIndexSourceManager.cs and a BodyIndexSourceView.cs the same way they made the Color/Depth/Infrared/BodySource data show in unity. I don't see the issue, but that's also because I've never worked with Byte-data in depth and there's little documented on what kind of data is actually received from the BodyIndexSource stream.</p>
  
  <hr>
  
  <p>Example codes:</p>
  
  <pre><code> public class BodyIndexSourceManager : MonoBehaviour
      {
  
      public int IndexWidth { get; private set; }
      public int IndexHeight { get; private set; }
  
      private KinectSensor _Sensor;
      private BodyIndexFrameReader _Reader;
      private Texture2D _Texture;
      private byte[] _Data;
  
      public Texture2D GetTexture()
      {
          return _Texture;
      }
      void Start()
      {
          _Sensor = KinectSensor.GetDefault();
          if (_Sensor != null)
          {
              _Reader = _Sensor.BodyIndexFrameSource.OpenReader();
              var frameDesc = _Sensor.BodyIndexFrameSource.FrameDescription;
              IndexWidth = frameDesc.Width;
              IndexHeight = frameDesc.Height;
              _Texture = new Texture2D(frameDesc.Width, frameDesc.Height, TextureFormat.RGBA32, false);
              if (!_Sensor.IsOpen)
              {
                  _Sensor.Open();
              }
          }
      }
  
      void Update()
      {
          if (_Reader != null)
          {
              var frame = _Reader.AcquireLatestFrame();
              if (frame != null)
              {
                  Debug.Log("frame not null");
                  frame.CopyFrameDataToArray(_Data);
                  _Texture.LoadRawTextureData(_Data);
                  _Texture.Apply();
                  frame.Dispose();
                  frame = null;
              }
          }
      }
  
      void OnApplicationQuit()
      {
          if (_Reader != null)
          {
              _Reader.Dispose();
              _Reader = null;
          }
          if (_Sensor != null)
          {
              if (_Sensor.IsOpen)
              {
                  _Sensor.Close();
              }
              _Sensor = null;
          }
      }
      }
  </code></pre>
  
  <p>Next class:</p>
  
  <pre><code>    public class BodyIndexSourceView : MonoBehaviour
  {
      public GameObject BodyIndexSourceManager;
      private BodyIndexSourceManager _bodyIndexManager;
  
      void Start()
      {
          gameObject.renderer.material.SetTextureScale("_MainTex", new Vector2(-1, 1));
      }
  
      void Update()
      {
          if (BodyIndexSourceManager == null)
          {
              return;
          }
  
          _bodyIndexManager = BodyIndexSourceManager.GetComponent&lt;BodyIndexSourceManager&gt;();
          if (_bodyIndexManager == null)
          {
              return;
          }
  
          gameObject.renderer.material.mainTexture = _bodyIndexManager.GetTexture();
      }
      }
  </code></pre>
  
  <p>I am probably just doing the wrong thing or overseeing something.
  Hopefully someone can show me some insight so I can continue! ^_^ Thanks in advance for any response given.</p>
  
  <p><strong>Summary:</strong>
  If you know what the best approach is to draw "only" the pixel-data of tracked bodies into Unity through Kinect One, please let me know or tell me what I am doing wrong for the start @ the code given above.</p>