Search Unity

  1. We are migrating the Unity Forums to Unity Discussions. On July 12, the Unity Forums will become read-only.

    Please, do not make any changes to your username or email addresses at id.unity.com during this transition time.

    It's still possible to reply to existing private message conversations during the migration, but any new replies you post will be missing after the main migration is complete. We'll do our best to migrate these messages in a follow-up step.

    On July 15, Unity Discussions will become read-only until July 18, when the new design and the migrated forum contents will go live.


    Read our full announcement for more information and let us know if you have any questions.

Question Can I create and destroy physics worlds dynamically at runtime?

Discussion in 'Physics for ECS' started by Paxonn57, Jun 11, 2023.

  1. Paxonn57

    Paxonn57

    Joined:
    Apr 27, 2018
    Posts:
    3
    I'm working on a project prototype where I would love to push entities into separate physics worlds so they can be simulated in groups I'm interested in without interacting with other groups.
    Obviously that can be easily achieved by just changing the value of PhysicsWorldIndex component but I need to create the physics worlds first.
    Documentation link
    I found this in the documentation but it's a solution that allows me only to create physics worlds before compilation/building/running/whatever.
    In my project I would need to create these physics worlds dynamically because due to it's nature at one point in time I might need just one physics world and at some different time 50 of them. Is it possible to create and destroy these Physics Worlds / Simulation Groups dynamically at runtime?

    One obvious solution would be to create all the worlds I assume I would need in the way shown in the linked documentation, have them running in the background and just use them when I need them but I just feel like it doesn't sound like ideal solution and idk what it would do to performance if I were to have 100 Physics Groups running in the background at all times even if empty.
     
  2. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    901
    I think you will run into performance issues with that many worlds. I am not sure what you are trying to do but think about using layers or putting all your predictive physics into a second world. If you want to run your sim in real time 50 worlds is probably too many.
     
  3. Paxonn57

    Paxonn57

    Joined:
    Apr 27, 2018
    Posts:
    3
    The simulations would be very light weight, I just can't have them interacting with each other
     
  4. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    901
    What's wrong with layers?
     
  5. Paxonn57

    Paxonn57

    Joined:
    Apr 27, 2018
    Posts:
    3
    Afaik I can only have ~32 layers which likely might not be enough for my needs
     
  6. TheOtherMonarch

    TheOtherMonarch

    Joined:
    Jul 28, 2012
    Posts:
    901
    So two or three worlds? Not 50 which is a unreasonable number.