Search Unity

spriteShapeController collider update problem

Discussion in '2D' started by vaibhav_unity235, Mar 19, 2019.

  1. vaibhav_unity235

    vaibhav_unity235

    Joined:
    Aug 22, 2018
    Posts:
    4
    in my game sprite shape controller points,spline,spriteshape are change by scripts its work properly but edge collider is not updating automatically when i click on that gameobject then it is update. or when i change sprite shape controller values in inspector manually in editor then collider update.
    but if don't click on that gameobject or not change value manually then its not update at run time.




    I have created a world generation system that includes Sprite Shapes. This system progressively generates a rope bridge using the sprite shape tool.

    This system works fine, but regardless of the changes made to the spline, the collider does not update. The collider is set to auto-update, and when I select the sprite shape in the inspector, the collider refreshes and works perfectly. I have tried all of the different functions available in the spriteshape controller, but none of them seems to update the edge collider.

    The spriteshape is instantiated from a prefab, then the startPos and endPos are set. The game then calls updateSpline(), shown below.

     
  2. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    @vaibhav_unity235 You could also call SpriteShapeController BakeCollider() function to generate collider on runtime while we look into the issue.

    // Simple code to demonstrate BakeCollider.
    public class AnimatePoints : MonoBehaviour
    {
    bool changesMade = false;
    void Update()
    {
    if (changesMade)
    GetComponent<SpriteShapeController>().BakeCollider();
    if (Random.Range(0, 10) % 2 == 0)
    {
    var pos = GetComponent<SpriteShapeController>().spline.GetPosition(0);
    pos.x = pos.x + Random.Range(-1.0f, 1.0f);
    GetComponent<SpriteShapeController>().spline.SetPosition(0, pos);
    changesMade = true;
    }
    }
    }
     
    maksdyachok2005 likes this.
  3. starfoxy

    starfoxy

    Joined:
    Apr 24, 2016
    Posts:
    184
    I am using SpriteShapeController BakeCollider() function as advised and it seems to be working well. Any updates on this as to whether I should be updating the edge collider differently?
     
  4. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    BakeCollider is the right function to update Collider.
     
  5. ImperialDynamics

    ImperialDynamics

    Joined:
    Jun 21, 2018
    Posts:
    21
    Nope. BakeCollider doesn't solve the issue for me