Search Unity

How to bake Sprite Shape?

Discussion in '2D' started by liamrobertson, Aug 22, 2020.

  1. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    Can't find documentation on this. What is the proper use of SpriteShapeController.BakeMesh()?

    I have called it in my script but I cannot tell if it is doing anything.
     
  2. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    First post on thread
    Sprite Shape 4.1.1 for Unity 2020.1

    Looks like the official docs aren't up to date yet. I dunno why my formatting changed :/
     
  3. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    I also noticed that BakeMesh() returns JobHandle, and if you don't write BakeMesh().Complete() then you can get a whole bunch of errors. But still I appear to be able to edit the spline.
     
  4. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
    You probably need to do it using the job system. I've never used it though so I'm not very sure.
     
  5. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    Yep, I also have no idea how the job system works ¯\_(ツ)_/¯ Hope the documentation is updated!
     
  6. spryx

    spryx

    Joined:
    Jul 23, 2013
    Posts:
    557
  7. ed_s

    ed_s

    Unity Technologies

    Joined:
    Apr 17, 2015
    Posts:
    165
  8. Venkify

    Venkify

    Unity Technologies

    Joined:
    Apr 7, 2015
    Posts:
    644
    Please take a look at this Video on usage of Bake SpriteShape Geometry feature


    If you want to explicitly use SpriteShapeController.BakeMesh() for any custom purpose, you may also need to Complete the Job.

    var handle= SpriteShapeController.BakeMesh();
    handle.Complete();

    However, could you please let me know the use-case ?
     
  9. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    @Venkify Thanks, it wasn't clear that the "Cache Geometry" button is baking the SpriteShape. I don't have any need to use BakeMesh() explicitly.

    I have levels with a somewhat complex SpriteShape (maybe somewhere between a few dozen and 100 vertices) where performance needs to be optimized for mobile. Before I was getting some fairly big spikes on Android from the renderer, but it seems fine now. Let me know if I'm going down the wrong path with this though.
     
  10. eddyabasiaada50

    eddyabasiaada50

    Joined:
    Jul 15, 2020
    Posts:
    1
    I think I am also having this same problem. I even checked this website but I was not able to get the reply I wanted. Please were you able to resolve it?
     
  11. liamrobertson

    liamrobertson

    Joined:
    Oct 28, 2015
    Posts:
    7
    Hey eddy. Doesn't look like that website would have solved your problem. But I think that the issue is solved by checking "Cached Geometry" on your SpriteShape from the inspector.

    Also, in a recent update they fixed an issue where SpriteShape required garbage collection on every frame. So make sure you are on the latest version of Unity, and you should be set.
     
  12. agabiisreal

    agabiisreal

    Joined:
    Sep 18, 2020
    Posts:
    1
    Sorry what was the solution to the question raised? Thanks