- Home /
AddComponent performance
Hi guys, i need to call destroy([componentname]) and addcomponent every time a bullet collides with the ground. I use polygoncollider2d and i have to reset it, because it updates its collider only when it has been reseted. Is there a faster way of doing this?
Answer by Simeon · Jan 28, 2015 at 06:10 PM
You should use Object Pooling.
Can I use Pooling for Components, like PolygonCollider2D? I don't need to reinitialize the whole gameobject again, only it's one component, to refresh the actual collider.
I though you wanted to destroy your bullets. But if you just want to change the polygon collider on a single object, then just do so. The collider should update automatically if you set the path Programmatically. But if you change the sprite itself, then unity does not update the collider.
I change the sprite itself, can i force Unity to update the collider somehow? If not could you please tell me how can I solve this problem?
i don't think there is a solution right now :X, you just have to stick to destroying and creating it again
Your answer
Follow this Question
Related Questions
Destroying a LineRenderer component and then adding it again at runtime 4 Answers
C# - Disabled Script Still Runs! 1 Answer
Clearing a LineRenderer Whiteboard, so that you can start drawing again 1 Answer
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
Difference between capitalized component in AddComponent and Destroy 2 Answers