Hello everyone, I have an update function below that is supposed to be tracking bodies from the Kinect.
However I have an issue where the _Bodies
Dictionary
doesn’t store anything and is always cleared when the Update
loop starts back from the top. Once it gets to this point:
List knownIds = new List (_Bodies.Keys);
_Bodies
is already at a count of zero. So the code that is supposed to remove a key value pair if it’s not being tracked by the Kinect anymore doesn’t run. Also this means that it just keeps instantiating new objects over and over again.
Can anyone see why my Dictionary
might not be storing values properly?
private Dictionary<ulong, GameObject> _Bodies = new Dictionary<ulong, GameObject> ();
void Update()
{
if (BodySourceManager == null) {
return;
}
_BodyManager = BodySourceManager.GetComponent<BodySourceManager> ();
if (_BodyManager == null) {
return;
}
Kinect.Body[] data = _BodyManager.GetData ();
if (data == null) {
return;
}
List<ulong> trackedIds = new List<ulong> ();
foreach (var body in data) {
if (body == null) {
continue;
}
if (body.IsTracked) {
trackedIds.Add (body.TrackingId);
}
}
List<ulong> knownIds = new List<ulong> (_Bodies.Keys);
// First delete untracked bodies
foreach (ulong trackingId in knownIds) {
if (!trackedIds.Contains (trackingId)) {
Destroy (_Bodies [trackingId]);
_Bodies.Remove (trackingId);
}
}
foreach (var body in data){
if (body == null) {
continue;
}
if (body.IsTracked)
{
if (!_Bodies.ContainsKey (body.TrackingId)) {
_Bodies [body.TrackingId] = InstantiateMyObject(body);
}
RefreshBodyObject (body);
}
}
}
_BodyManager = BodySourceManager.GetComponent<BodySourceManager> (); Put that in Start(). So, whats this RefreshBodyObject and whats in that BodySourceManager? Could they cause the problems?
– DemocritusSo, I should try switching to "v2f vert (appdata v)" and calculate transforms using something like this: v2f o; o.vertex = mul(UNITY_MATRIX_MVP, v.vertex); If i understand you correctly.
– Titty