- Home /
How does OverlapAreaNonAlloc (non) allocation works?
Hi there, I have a question regarding OverlapAreaNonAlloc. I'd like to use it for collision detection. The part I'm not sure I understood is this (quoted from documentation):
"but the results array will not be resized if it doesn't contain enough elements to report all the results."
This basically means that if my character can collide with, let's say, a maximum of 2 ground elements at the same time (think of it as different platforms), then I should allocate a Collider2D[] for two elements (or more, in other case scenarios) explicitly, before passing the array as a parameter of OverlapAreaNonAlloc?
Thanks.
Answer by MelvMay · Apr 03, 2016 at 12:08 PM
It's pretty simple; you allocate the array, it'll only fill up to the size of the array or the number of results (whichever is lowest).
Don't allocate an array each time you call it otherwise that'd defeat the purpose right?
Allocate a relatively large one once up to the size of results you're interested in and reuse it. Doing that means there's no garbage collection.
Your answer
Follow this Question
Related Questions
Bullets go through collider even with continuous collision detection! 0 Answers
Physics2D.CircleCast result doesn't match with actual circle object's collision detection 0 Answers
After Collision Matrix change in runtime, effects not immediatly visible 1 Answer
Is Overlap Circle Supposed to return inactive colliders? 1 Answer
Problem with 2D collision detection (Wide object falls through a thin hole) 1 Answer