Hi there.
I use serilazation from xml and want to create sprites in runtime. My strategy is follow:
1. Instantiate sprite from sprite prefab.
2. Select proper spriteid and collection (call SwitchCollectionAndSprite).
3. After this sprite images are changed, but collider are not created properly - collider is still from old sprite.
4. Call ForceBuild(). After this new collider will be created.
But step 4 occurs to "Invalid mesh collider on sprite, please remove and try again." error.
In this post:
http://unikronsoftware.com/2dtoolkit/forum/index.php/topic,1131.msg5381.html#msg5381 I read that it's error in unity and it's not a fatal and it's resolved in short time.
But it's in editor mode - I create sprite in runtime, so perfomace is not clear for me - I have 90 errors in editor console for one level load (1 error for one sprite creation).
Can this lead to application crash? Should I wrap this in try-catch (but in this case I will have >90 call of catch block and it's very perfomance expensive).
Maybe exists some workaround for this stuff (Create sprites in runtime with different collider types)?
I see that EditMode__CreateCollider() did not lead to exceptions or errors, but it annotated as call only in editor. Can I use it (with modification of course)?
Thanks in advance.
Update:
ForceBuild works in Editor but does not work on release build (win standalone) - collider from old sprite is still exist.
I modified EditMode__CreateCollider() method (remove #if Editor directives) and call it from script instead ForceBuild() - seems like issue fixed.
I will try this workaround on Android and let you know about results.