Search Unity

Confused about api access

Discussion in 'Physics for ECS' started by snacktime, Nov 20, 2019.

  1. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Why are there things like Broadphase.ScheduleBuildJobs() that are public and even talked about in the release notes, but impossible to use because things they rely on are internal?

    Fyi to use custom worlds the two things currently that have to be modified are StaticLayerChangeInfo and CollisionWorld.Broadphase.
     
  2. Rory_Havok

    Rory_Havok

    Joined:
    Jun 25, 2018
    Posts:
    70
    Thats a fair point. Custom worlds are not yet exercised in our demos so we just missed the fact that Broadphase.ScheduleBuildJobs() is public right now but StaticLayerChangeInfo is not.

    The plan is absolutely to make more of the API public, but we are currently erring on the side of being conservative by keeping some things internal until we are confident that those APIs won't change afterwards. Broadphase.ScheduleBuildJobs() is also good example of one that likely will change when we do start using it more, since StaticLayerChangeInfo is not a friendly API.

    I expect more APIs to become public soon as part of some work to allow creating and stepping worlds within a single job.
     
    steveeHavok likes this.
  3. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    I think the amount that is restricted is a bit much, I just keep hitting so much of it.

    As it is now it's just causing unnecessary pain IMO. A lot is really just unexpected, and by the time you hit it, the correct solution is modify the source. The alternatives will often be far worse. Like either walk away from Unity.Physics or duplicate internal logic.

    I think a good measure is if your own tooling needs internal access, it shouldn't be internal.
     
    MNNoxMortem likes this.
  4. telpe_night

    telpe_night

    Joined:
    Oct 7, 2017
    Posts:
    4
    Please, also consider to give access to LowLevel.CollisionEvents and LowLevel.TriggerEvents somehow. They are handy for custom worlds too. For example for collecting events without using Job System, while simulating several step ahead.
     
  5. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Hey, as part of the new release we will be adding interfaces to do the Broadphase work through CollisionWorld, so you won't need access to Broadphase at all.

    Also, we will be adding support for iterating through events without jobs, but using the foreach loop instead. :)
     
  6. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So looking at the abstraction we have for building isolated static worlds, the current api needs StaticLayerChangeInfo which is internal as you noted above, and that needs the static body count so I'm accessing PhysicsWorld.StaticBodies to get that. I'm also calling PhysicsWorld.Reset but it's been a while and not sure if I actually tested that as being necessary.

    I'm assuming that's all now encapsulated through CollisionWorld?
     
  7. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    So FYI on our flow we are writing directly to PhysicsWorld.StaticBodies. We have our own bodies array that we update first. When it changes we then call PhysicsWorld.Reset to it's length. Then run IJobParallelFor to copy our bodies to PhysicsWorld.StaticBodies which chains into BroadPhase.ScheduleBuildJobs.
     
  8. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    StaticLayerChangeInfo is going away, so this interface will be much simpler, you won't have to worry about any of that with the coming release. Of course, the ability to skip rebuilding the static tree will still be there, only through a much simpler interface. We are aware that StaticLayerChangeInfo was a bit unintuitive, thus the whole rework.
     
  9. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    I know I'm lttp on this, but I wanted to make sure we had explicitly addressed this to shed some light on our thinking (feedback of course welcome).

    If we have made something part of public API it means that we are committed to maintaining it as best as possible. In addition to fixing bugs and ensuring all behavior is specified, it means that we will add obsolete API updaters when possible if something changes or is removed, and so on. Basically it means (while we're in experimental) that we're pretty confident it will not change, or that we can bear the cost of mitigating user pain if it needs to change.

    On the other hand, if something is internal or private, it just means we have not yet had sufficient development resources to vet the design in order to confidently estimate and commit to these maintenance costs. It gives us more flexibility to prioritize other things, break things, make significant/disruptive changes, or only validate behavior with a limited range of use cases because we haven't made explicit contracts with users. (The situation with StaticLayerChangeInfo is one such example.)

    The long-term vision is to make as many internal structures public as is reasonable (i.e. adds value for users), but it hasn't been the most urgent priority yet. So for now we continue to recommend that advanced users make and maintain local modifications, and provide feedback about how they're using these internals to solve problems.
     
    Last edited: Mar 5, 2020
  10. telpe_night

    telpe_night

    Joined:
    Oct 7, 2017
    Posts:
    4
    Thank you for fixes these issues in latest update)
    Please, also consider making some internal tools like DisplayBodyColliders.DrawComponent public. This class is perfectly usable outside of ECS and is very handy. :)
     
    petarmHavok likes this.
  11. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Thanks for the feedback! The debug drawing systems in particular are going to be undergoing some changes in the coming releases, so I wouldn't expect any changes to access there until after that work has happened.
     
    optimise likes this.
  12. tarahugger

    tarahugger

    Joined:
    Jul 18, 2014
    Posts:
    129
    Please also consider exposing low-level collider functions, for example; if a user wants to make an arbitrary OBB collider and test the distance to points. Collider use outside of the full system could be useful for many things and currently we'll either have to keep our own modified copy of the package or build a secondary system just for these cases and neither are good options.
     
  13. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    That reminds me. Maybe consider abstracting out iterating over different collider types. It's useful on it's own. We lifted a lot of that code to create geometry collection abstractions that we use in our own navigation mesh system. Probably other uses as well.