#component crashes if i add it to more than 5 game objects at the same time

2 messages · Page 1 of 1 (latest)

delicate sonnet
#

so i have a unity script that i want to use on all of my colliders, but if i add it to all of them, it causes unity to freeze. so my plan is to create a method where i can 1 by one add them and wait maybe 1 or 2 frames then remove them and repeat that for every collider, totaling up to around 300 different colliders.
is there a way to:

  1. call the script to do something similar to a coroutine in the editor so i can have it pace itself as it iterates through every collider
  2. bring a progress bar so i can see how long it may take

long story short, i found a pretty decent polygon collider editor that allows me to auto update my colliders to be a bit closer to pixel perfect, but it really causes everything to crash if i dont pace it.

brazen fiber
#

You could create your own editor window with an execution button and progress bar using the OnGui method, see this page for reference: https://docs.unity3d.com/ScriptReference/EditorGUI.ProgressBar.html

As far as actually executing your editor script, you could use the c# task library and create a task for each collider, have each one update a static counter so that you can update your progress bar, and use Task.WhenAll to ensure that they are all ran. Doing it this way also ensures that your editor doesn't freeze as the task library runs everything asynchronously!