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

Multiple isolated physics worlds vs layers

Discussion in 'Physics for ECS' started by Jawsarn, Apr 21, 2020.

  1. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    So what would be the best approach for doing isolated physics worlds? In my case I have spaceships with interiors where you can walk around inside. Currently I'm using different layers, but it's in the current shape a hassle to set up with a prefab variant for each world with it's separate layer. I'm also considering having one layer where all interiors exist, but are offset to not interfere with eachother. Any ideas?
     
  2. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    699
    I'd also be interested in a primer for this, somehow UnityPhysics creates and simulates a physics world for us, but maintaining your own is not explained. (especially how to move entities from one to another, or to run a job system that performs this copy)

    Also using this for space, but rather for physics bubbles in a floating origin system.

    I've been thinking about layers/filters, but it won't work well and doesn't arbitrarily scale.
     
    Jawsarn likes this.
  3. Adam-Mechtley

    Adam-Mechtley

    Administrator

    Joined:
    Feb 5, 2007
    Posts:
    290
    Yes unfortunately it is not something for which there are scaffolds at the moment. We have some plans to do something data driven in the future (so you could e.g. simply designate a body's membership in a particular physics world via a component), but no work has yet begun on this. In the meantime, you would have to follow the example of something like the SingleThreadedPhysics test we have in the sample project, where you just use the same type of data in your own system that matches a different query from that in the built-in systems
     
  4. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Multiple ECS worlds for physics (or anything really) is a hard problem pretty much anything else is better. For this anything that needs to talk to it needs to be isolated in the same world also or you just bought yourself a lot of additional pain. It's one of those ideas that seems great at a high level but has a lot of caveats once you get to the details. Like rendering and physics both use transforms. And you have your gamelogic mixed in. As a general rule going down that path won't end well, there are very few cases where it's a good solution right now.

    Multiple Physics worlds has definite use cases, but mostly just for static geometry at this point until they support simulating multiple physics worlds within the same ECS world.

    For both of the use cases above though even if multiple worlds were baked in you would still need to reason about position offsets. Worlds would make that a bit easier but it's not really that hard without them. Find non conflicting areas you can use. Transform your entities to those. Have a component on each entity with their current offset for example.
     
  5. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    699
    snacktime, exactly - I am struggling with linking entities across worlds, which is why I discarded the idea for now.

    Got enough stuff to work on in one world, and the systems wouldn't change much.

    I think it's possible to just "port" the existing Unity Physics to use a list of worlds, but that would mean every significant change requires a backport. Lots of margin for errors.

    I'd rather like to see physics and presentation systems work in harmony, I got juddering rigidbodies all over, and wonder if I'm maybe changing my velocities in the wrong parts of playerloop.
     
  6. Jawsarn

    Jawsarn

    Joined:
    Jan 12, 2017
    Posts:
    245
    Any updates on this topic?
     
  7. marcAKAmarc

    marcAKAmarc

    Joined:
    Dec 16, 2014
    Posts:
    7
    I'm accomplishing this by running physics simulations for each isolated physical environment in a new scene.

    When a physical body enters a new ship interior (for example), a copy of that body is entered into a new scene that simulates the physics of the ship interior. These physical bodies here are completely isolated from the main scene. Then I just map any updates from the copy of the body in the physics simulation back to the main scene.

    It takes a bit of elbow grease, but it works.
     
  8. marcAKAmarc

    marcAKAmarc

    Joined:
    Dec 16, 2014
    Posts:
    7
  9. Spy-Master

    Spy-Master

    Joined:
    Aug 4, 2022
    Posts:
    507
    These have nothing to do with Unity Physics.
     
  10. marcAKAmarc

    marcAKAmarc

    Joined:
    Dec 16, 2014
    Posts:
    7
    Lol you are totally correct. Didn't realize this was unity physics related and not PhysX.