Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Why does SpriteRenderer.SetSprite call Physics2D.CreateShapes?

Discussion in 'Physics' started by ercion, Dec 18, 2018.

  1. ercion

    ercion

    Joined:
    Aug 15, 2016
    Posts:
    73
    The profiler tells me that
    SpriteRenderer.SetSprite_INTERNAL()
    is calling
    Physics2D.CreateShapes
    and
    Physics2D.DestroyShapes
    . Why is it so? How can I prevent/optimize it? This happens when I call
    SpriteRenderer.sprite = NewSprite
    on an object with RigidBody2D, and a BoxCollider2D.

    Capture.PNG
     
  2. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    Do you have "Generate Physics Shape" enabled for those Sprites?

    screenshot.png
     
  3. ercion

    ercion

    Joined:
    Aug 15, 2016
    Posts:
    73
    @Peter77 I don't see that option in my Inspector. I'm using Unity 2017.2.0p2.
    This is what I see in the inspector:

    Capture.PNG
     
  4. Peter77

    Peter77

    QA Jesus

    Joined:
    Jun 12, 2013
    Posts:
    6,589
    I made the screenshot with Unity 2018.2.19f1.
     
  5. ercion

    ercion

    Joined:
    Aug 15, 2016
    Posts:
    73
    I see. Any suggestions on how to optimize sprite animation done through C# script? I have thousands of animated objects and I'm animating them through a single script. Kinda like old school ECS :D