Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Feedback Add a remark for Physics cast methods

Discussion in 'Documentation' started by BakeMyCake, Dec 23, 2020.

  1. BakeMyCake

    BakeMyCake

    Joined:
    May 8, 2017
    Posts:
    175
    I've spent more time than I'd like to admit, debugging a strange case where my BoxCast-dependent code would suddenly teleport objects to the origin of the world. The issue turned out to be an unexpected feature of the API that all functions working with RaycastHit can potentially return 0 as the hit point.

    I believe this is not apparent from the API documentation and should be warned about. I did not find any mention of it in any of the documentation I initially searched:
    https://docs.unity3d.com/ScriptReference/Physics.BoxCast.html
    https://docs.unity3d.com/ScriptReference/Physics.BoxCastNonAlloc.html
    https://docs.unity3d.com/ScriptReference/RaycastHit.html
    https://docs.unity3d.com/ScriptReference/RaycastHit-point.html
    https://docs.unity3d.com/ScriptReference/Physics.Raycast.html

    The only place I've found, where this is described is here
    https://docs.unity3d.com/ScriptReference/Physics.SphereCastAll.html
    After discovering this I was able to locate a lot of forum discussions describing and explaining it in detail, the problem here is that at that point I've already lost time debugging it myself. This is a classic case of something incredibly simple being difficult to discover naturally by virtue of not knowing the magic keywords to type in search beforehand. To save anyone else the trouble I suggest mentioning this nuance in more places in the API documentation to improve user experience.

    As it stands, it seems you can only discover this either by running head-first into the very same issue, or if you happen to be using SphereCastAll specifically.