- Home /
Kinect data retrieved on Update() call not available on LateUpdate() call.
I have a game component KinectManager which I use to manage the connection to my Kinect sensor, plus pull data from it by storing updated sensor data in a publicly exposed Body[] property. The Body[] property gets repopulated every time the component's Update() method is called:
void Update()
{
if (_bodyFrameReader != null)
{
var frame = _bodyFrameReader.AcquireLatestFrame();
if (frame != null)
{
if (_bodies == null)
{
_bodies = new Body[MaxNumberOfPlayers];
}
frame.GetAndRefreshBodyData(_bodies);
//frame.Dispose();
//frame = null;
}
}
}
The _bodies attribute is exposed publicly here:
public Body[] GetData()
{
return _bodies;
}
public Body GetData(int playerIndex)
{
if (null == _bodies)
{
return null;
}
return _bodies[playerIndex];
}
I have another game component which is attached to the KinectManager game component by storing it in a public property set by the Unity3D editor. This game component, the LeftHandController, reads the data stored in _bodies on every LateUpdate() call:
protected void updateLeftHandPosition()
{
//_playerBody = _kinectManager.GetData(PlayerIndex);
Body[] bodies = _kinectManager.GetData();
_playerBody = bodies[PlayerIndex];
if (null == _playerBody)
{
return;
}
Windows.Kinect.Joint leftHand = _playerBody.Joints[JointType.HandLeft];
transform.position.Set(leftHand.Position.X, leftHand.Position.Y, transform.position.z);
}
public void LateUpdate()
{
updateLeftHandPosition();
}
However, every time my LeftHandController.LateUpdate() is called, the data from _kinectManager.GetData() always returns as:
ObjectDisposedException: The object was used after being disposed. Windows.Kinect.Body.get_Joints () (at Assets/Standard Assets/Windows/Kinect/Body.cs:290) StupidFun.LeftHandController.updateLeftHandPosition () (at Assets/StupidFun/LeftHandController.cs:41) StupidFun.LeftHandController.LateUpdate () (at Assets/StupidFun/LeftHandController.cs:59)
Why?
Your answer
Follow this Question
Related Questions
Crease Image Effect not working with DX11 and Render Texture 0 Answers
aldonaletto 0 Answers
kinect + unity to tracking or detect people from side, not front. 2 Answers
How to use gestures to perform a specific activity in unity using kinect? 1 Answer
Converting Kinect depth coordinates to work with Unity 0 Answers