Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Change Profile of SpriteShapeController by code

Discussion in '2D' started by UnityProdS, Oct 2, 2023.

  1. UnityProdS

    UnityProdS

    Joined:
    Jan 11, 2014
    Posts:
    35
    I have made a SpriteShapeController and attached a Sprite Shape profile to it, now I want to change this Profile at runtime.

    I am trying to access the Profile like this on the SpriteShapeController Gameobject
    GetComponent<SpriteShapeController>().....
    I don't see any option to choose Profile here so that I can chase it by code. See the screenshot below in terms of where I want it to change dynamically.

    Looking forward to some guidance and help.
     

    Attached Files:

  2. Baste

    Baste

    Joined:
    Jan 24, 2013
    Posts:
    6,179
    You can set the public property named
    .spriteShape
    . It's a bit confusing that the actual type name of what's called SpriteShapeProfile in the UI is just "SpriteShape".

    After you set it, you want to call RefreshSpriteShape() on the Controller, which causes it to realize that it has to rebuild things.
     
    Venkify likes this.
  3. UnityProdS

    UnityProdS

    Joined:
    Jan 11, 2014
    Posts:
    35
    Thank you @Baste That was very helpful. It works perfectly fine. Thanks again!