Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Collider OnTriggerEnter with SendMessage

Discussion in 'Physics' started by sstrong, Nov 13, 2020.

  1. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,219
    After a Physics.OverlayCapsuleNonAlloc I'd like to send OnTriggerEnter/Exit/Stay events to a collider. This works with the following code snippet.

    Code (CSharp):
    1. otherCollider.SendMessage("OnTriggerEnter", otherCollider, SendMessageOptions.DontRequireReceiver);
    However, I'm wondering if there is a more efficient method. I'm assuming that SendMessage has to do the following:
    1. Look up all the MethodInfo's on the target collider component
    2. Potentially perform a string comparison on the name for each Method (incurring GC overhead)
    3. When (if) it finds one, check to see that the number of arguments and their types match