1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

UnityPhysicsとColliderに関する注意点

Last updated at Posted at 2024-08-11

StaticオブジェクトにRaycastがヒットしない

ECSでJobのスクリプトを書いているときにraycastを使いたい場面は沢山あると思いますが、MonoBehaviorで使っていたRaycastALLとかは残念ながら使えないので、CastRayを使うことになります。
※詳しくは、以下ページの「7. Queries/Query - Custom Collector.unity」を参照
https://github.com/Unity-Technologies/EntityComponentSystemSamples/blob/master/PhysicsSamples/README.md

しかしながら、CastRayを使ってもヒットしなくて直近ハマったので、備忘録として残します。

結論から言うと、原因はColliderがアタッチされていることでした。
以下のようにBoxColliderがついていると、なぜかそのEntityにはCastRayが反応しない。
※しかも非アクティブ状態なのに...!!
image.png

とにかくECSを扱うとき、不要なColliderは全て除去しましょう。非アクティブ状態でもね。
2024/12/14
原因は、Colliderがついていると、Collider有無でEntityにLocaltransformのCompornentが付与されるかどうかが、変わってしまうためでした。
例えば通常PhysicsShapeがついていると、Localtransformも付与されますが、
BoxCollider(非アクティブ状態)が付与されていると、アクティブ状態のPhysicsShapeが付与されていても、LocaltransformがEntityにつきません。

恐らく今後のUnityのアップデートで修正されると思いますが、ひとまず要注意です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?