Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How do i implement system similar to the "sleep" of the Rigidbody component?

Discussion in 'Physics for ECS' started by ops0606, Oct 9, 2023.

  1. ops0606


    Dec 6, 2016
    I'm aware that Havok already supports sleep. However, purchasing the Pro license is a bit burdensome for me, so I'm trying to implement it, albeit crudely.

    Firstly, I've implemented the terrain using a single large Mesh Collider.
    A very large number (more than 50,000) of sphere colliders come into contact with this terrain.
    In terms of game logic, they don't always move, so I don't want to use PhysicVelocity when they're idle.
    However, the frequency of movement is too ambiguous to add/remove components.
    How can I optimize this?

    And Would splitting the Mesh Collider help with optimization?
  2. daniel-holz


    Unity Technologies

    Sep 17, 2021
    Hi! What exactly is your goal here? Are you looking for performance gains?

    In order to disable the spheres which fall asleep manually you could move them to another physics world by changing the Value in their PhysicsWorldIndex component to anything but the default 0.
    However, waking them back up will prove difficult if it should be based on collisions since the spheres won't be tracked by the collision detection anymore if they are moved to a separate non-simulated physics world this way. As a simple solution, you could wake them up simply based on proximity with some specific region of interest, e.g., a "player". When a sphere becomes close enough to that moving region you bring them back into the default physics world.