I suspect this is the same problem we had with forceandtorque callback.
Basically the problem is that GameObjects(and it's components) can't be accessed from outside the main thread.
Maybe dNewtonWorld::OnContactCollision could collect all collisions in an array and then loop through that array and trigger the gameobject OnCollision events/calls after NewtonUpdate.
I guess that would be the same as iterating through the contacts though and we loose the ability to modify the contacts during the simulation step.
Would it be possible to split up NewtonUpdate into two phases?
Like a collision phase and simulation phase? I don't know the internals enough of Newton to know if that's even possible.
So that updating Newton from C# would take two calls.
Something like this...
NewtonUpdateCollision(world, timestep)
//Collect and trigger collision events here
NewtonUpdateSimulation(world, timestep)
//Update transforms here...
Forget the above if it sounds idiotic, just throwing ideas.
[EDIT]
I think it's hanging for some other reason though.
If I change the declaration of the callback function(and the delegate) to this...
- Code: Select all
void OnCollision(IntPtr otherBody)
{
Debug.Log("collision"); // This works
//Debug.Log("collision " + this.gameObject.name); // This cause Unity to hang
}
That is, intptr instead of dNewtonBody as parameter.
But as soon as I try to access the gameobject Unity hangs.
So i guess, the user can manipulate the contact as longs as they don't touch the gameobject in any way.