Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Reuse support for MonoBehaviour.OnControllerColliderHit(ControllerColliderHit) argument

Discussion in 'Physics Previews' started by petrse, Sep 3, 2019.

  1. petrse

    petrse

    Joined:
    Oct 29, 2014
    Posts:
    3
    Hello,
    not sure if this is the right forum, anyway, a while ago Unity added Physics.reuseCollisionCallbacks option which allows us to get allocation-free OnCollision/Enter/Stay/Exit events. However a similar MonoBehaviour.OnControllerColliderHit(ControllerColliderHit) callback is not covered by this or any other option and still mandatorily allocates the ControllerColliderHit argument every invocation.

    Are there plans to support argument reuse for this callback as well and make it allocation free?

    Petr
     
  2. forestrf

    forestrf

    Joined:
    Aug 28, 2010
    Posts:
    229
    This may be related to OnControllerColliderHit being called inside Move() and the ability to call Move() yet again from inside OnControllerColliderHit, which means a single instance of ControllerColliderHit can't be used.

    BUT ControllerColliderHit could be a struct instead of a class (that would fix the problem) or Unity could allow a callback to be passed alongside the Move function. Still, it's not something we can fix, which renders OnControllerColliderHit unusable.