Search Unity

Feedback SpriteShapeController.BakeCollider does not bake the collider

Discussion in '2D' started by Baste, Nov 10, 2020.

  1. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,334
    SpriteShapeController has a public method named "BakeCollider". It doesn't bake the collider. That's pretty annoying when you need the collider to be up to date in order to post process it!

    In particular, it only bakes the collider if "Update Collider" is checked, and if the collider data "is created". If that's the case, the collider is baked, and then the collider data is immediately disposed.

    Worse, the method is only called from OnWillRenderObject, and relies on the bake job having been completed earlier. So in order to post process properly, I have to:

    Code (csharp):
    1.  
    2. controller.BakeMesh().Complete();
    3. controller.BakeCollider();
    4. PostProcess();
    5.  
    If I don't do that, the collider used during the PostProcess stage is outdated.

    I'm running the code above in OnInspectorGUI on an editor on the same GameObject as the SpriteShape, so in order for my code to work, I have to just hope that OnInspectorGUI gets called before OnWillRenderObject...
     
    Thorax- likes this.