Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

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.