Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice
  2. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  3. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Creating a ConvexCollider from data which is already convex and optimized

Discussion in 'Physics Previews' started by Baggers_, Aug 12, 2020.

  1. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    I have mesh data for a convex collider. It's definitely convex, and it's definitely optimized. How can I made a ConvexCollider using this data without having Unity try and optimize it again?

    From this post https://forum.unity.com/threads/how...out-any-performance-hits.777818/#post-5294382 it almost sounds like ConvexHullBuilder used to be public, but it isn't in preview-0.3.2.

    I could use BlobAssetReference<T>.Write to serialize it and load that, but then the asset format for my game's mods is now directly tied to the structs data layout, which is 'hidden' (of course I can get it there by editing the code or reflection, but that kinda defeats the point).

    I guess this question could be rephrased as "Why is the collider API seeming so intent on data hiding?", but that is less actionable in a thread. I'm loving how much less of that there is in the DOTS APIs in general. It would be really helpful to see this loosened up. There can still be a friendly front end on this system while leaving the door open to folks who would like a little more direct access.

    Great work though, really liking Unity.Physics so far.
     
    Last edited: Aug 12, 2020
  2. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Hey!

    Just to clarify, we are not intentionally hiding things, we are just trying to only make things that we designed well public. We'd hate to expose something early and then redo it in a few months, forcing you to change code. That's why some of the Unity.Physics APIs are still internal, but we are always working on making more stuff public.

    I think it's safe to say you can make anything you need public and come back to us with a reasoning behind it and a use case, and we can work on prioritizing making that public.

    We've already done the same with all the Broadphase functionality for people who don't need to step, just build BVH and query.
     
  3. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    @petarmHavok Thanks and sorry if I was accusatory there. I've been so enjoying the ability to roam free in the internals of Collections & Entities that seeing private/internal again got me worried.

    I'm working on a user-generated content game. Asset packs are loaded on demand at runtime, and among the data in there are colliders. The asset packs are composed ahead of time, and so we have the opportunity to generate the optimized convex meshes then and store that data in the asset packs. Doing so would mean we can avoid these costs when we load the AssetPack.

    It looks like I can use the Create methods from jobs, which helps, but if I can spend fewer cycles and still give the physics engine what it wants directly, that would be preferable.

    This is slightly tangential, but another reason that having more access to the data would be helpful would be so we can visualize the generated mesh as a check to see if there are any gameplay implications of the simplification. Odds are that it would be fine, but it would allow us to tune parameters or the source mesh to get a more ideal result.

    This may already be supported in the ECS or sub-scenes, but those tools don't fit our project's needs (as cool as they are).

    Thanks for your patience with my earlier brashness.
     
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Not at all, it was a completely reasonable thing to question, I'm just glad we sorted out the fact that it's just current state and in no way our plan in general.

    So you've probably noticed that ConvexCollider.Create() takes in the simplification parameters and those can be turned off (just set the tolerances to values that will have them skipped). However, it won't help with the cost, it will just produce the same result. We haven't really provided ability for users to control simplification (other than modifying code), the same applies for meshes where we've also got asks to do so.

    We're just coming from the standpoint of ensuring physics runtime is optimal, at the cost of a little extra time when creating the worlds. But it makes sense to provide optimization options even for creation, if people are sure they know what they're doing. I'll definitely put this on our list of things to do in the near term.

    And thanks again for the feedback on this!
     
  5. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    petarmHavok likes this.