UnityPhysics高速化についてのメモ

  • 基本的にCommandBufferではなく、CommandBuffer.Concurrentを使う。

CollisionEventsJobやTriggerEventsJobでは、

[NativeSetThreadIndex] private int _threadIndex;

のように宣言するとスレッドの番号を入手できるので、これをCommandBuffer.Concurrentの第一引数にjobIndexとして代入する。

そうするとWaitForJobGroupIDに割かれてしまっていた処理時間を削減できる。

  • CollisionFilterを使う

PhysicsShape -> CollisionFilter でBelongs ToとCollide With の項目を設定しておく。

そうすると、NarrowPhase:ProcessBodyPairsJob に割かれていた大きな処理時間をかなり削減できる。