I have another problem, for some reason, I can’t access PolygonCollider2D.points[whatever] variable. Don’t you know how to use those variables properly? Do I need to predefine them?
PollygonCollider2D.GetTotalPointCount() does not work for me too.
Is there a finite number of times a PolgonCollider2D can be added and destroyed? For some reason our sequence works fine for a limited period, then freezes. Is the destruction of those subject to a race condition that we can flush or wait for?
Eventually you would run out of memory, unless you clear unused assets with Resources.UnloadUnusedAssets. It would probably be better to not create/destroy polygon colliders, but just change the points instead.
Is there a way to change collider points without adding a new PolgonCollider2D? I gather setPath would do that, but the new points around the sprite are provided by the add PolgonCollider2D. Is there another way to extract those points from the sprite?
The collider also serves to extract the boundary of the sprite. Is there an explicit, transient function to do that so the same collider can keep getting updated points?
Do you mean you’re constantly destroying the collider so you can build a new one with the new auto-generated shape? That’s definitely not efficient; even if there was an AutoComputeColliderFromSprite function (which sadly there isn’t, or at least it’s not public), it would be faster to keep the auto-generated colliders in arrays, and apply them as needed. Although that will only work if you have a set number of pre-defined shapes (like a series of animated frames).
It is a continuous number of organically generated shapes. We can create our own evaluator if necessary, but it would be more efficient to access the private method already used by the collider if it can be exposed. I assume we can then keep resetting the path in a single collider.
Is there a way to access the internal, (AutoComputeColliderFromSprite function), sprite evaluator? Does anyone know the actual name for the private function in PolygonCollider2D that performs that function?