2

I built a Random Generated Mini Game with SpriteShape Prefabs. The Random Generator moves and changes the Spline of the SpriteShape. But the Edge Collider 2D refreses its size only when I click on the Instantiated Prefab on the Hirarchy.

What can I do to Refresh the Collider


This is the Scene when the World just generated. All Colliders are on the left side. enter image description here


This is the Scene after I clicked on the first 2 generated layers. The 2 Colliders Refreshed its size to the SpriteShape enter image description here


This is our code:

        GameObject currentLayer;
        Spline spline;
        int lastXPos = Random.Range(1, maxXPos-2);

        currentLayer = Instantiate(layer);
        currentLayer.transform.parent = gameObject.transform;
        currentLayer.transform.localPosition = new Vector3(0,-(2+i*2));

        spline = currentLayer.GetComponent<SpriteShapeController>().spline;
        spline.SetPosition(0, new Vector3(0, 0));
        spline.SetPosition(1, new Vector3(lastXPos, 0));
dasKamel
  • 59
  • 6
  • Try to disable and enable the collider to refresh it or Destroy the collider component and add a new one. You can read more about this issue in this forum: https://answers.unity.com/questions/722748/refreshing-the-polygon-collider-2d-upon-sprite-cha.html – Dave Apr 09 '19 at 13:04

1 Answers1

0

Currently, the auto update collider has a few bugs here and there. The best way would be to manually bake the Colliders in the script. just call the BakeCollider() Method. under SpriteShapeController should do the work.