Search Unity

Resolved How to hide entity from simulation, and then unhide it

Discussion in 'Physics for ECS' started by GameDeveloper1111, Jan 22, 2021.

  1. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    Resolved

    Physics-only exclude:
    Universal exclude:
    Original post

    Hi, I've got a cube that I want to smash into pieces. I've got the pieces, too, but I want to hide them from the simulation until the cube should be smashed.

    What's the recommended way to hide an entity from the simulation until it's ready to be simulated?

    Idea 1: Collision Filter

    Set "Collides with" of the "Collision Filter" of each piece to "Nothing" (and set gravity to zero). Then set it to "Everything" (for example) when the simulator should process them (and set gravity to default).

    Counter-thought: Maybe this would add waste to the broadphase of the physics simulation, by making it check for overlaps between the pieces and other bodies despite the pieces not being ready yet.

    Counter-counter thought: Maybe the simulator completely ignores those with the "Nothing" setting under their "Collides with" field.

    Idea 2: PhysicsCollider

    Add "PhysicsCollider", "PhysicsVelocity", and so on to each piece when the simulator should process them.

    Counter-thought 1: Have to do it from code instead of using the nice PhysicsBody GameObject authoring component.

    Counter-thought 2: Maybe it's expensive to do all those structural changes.

    Idea 3: Second world

    Create some sorta second sleepy physics world, from which one can pull physics entities into the main world to be simulated.

    Idea 4: Subscene

    Load a subscene that has all the pieces ready with PhysicsColliders and everything.

    Thanks for any replies!
     
    Last edited: Feb 16, 2021
  2. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    EDIT: Correction: HybridRenderer 0.11 supports lightmaps.

    Original reply

    The Subscene idea seemed great but doesn't seem to work without the HybridRenderer. I'm using Mesh Filter + Mesh Renderer instead of the HybridRenderer because the latter doesn't support lightmaps yet.

    I could try to re-establish the connection between each entity with each GameObject. I was using Convert-and-Inject to establish the connection but this goes away with subscenes.
     
    Last edited: Feb 5, 2021
  3. steveeHavok

    steveeHavok

    Joined:
    Mar 19, 2019
    Posts:
    481
    On the Physics side you can add a
    PhysicsExclude
    component to any Entity you don't want included in the simulation.
     
    PhilSA and GameDeveloper1111 like this.
  4. petarmHavok

    petarmHavok

    Joined:
    Nov 20, 2018
    Posts:
    461
    Also in the Material you have CollisionResponse, you can set it to None and change it when the time comes. But Steve's suggestion is definitely more efficient as it skips more steps.
     
  5. GameDeveloper1111

    GameDeveloper1111

    Joined:
    Jul 24, 2020
    Posts:
    100
    The Disabled component excludes an entity from all systems, by excluding them from all EntityQueries.

    EntityManager.SetEnabled(entity, false) adds the Disabled component.

    This could be overkill for some use cases but I thought I'd mention it here.
     
    Last edited: Feb 4, 2021
    steveeHavok likes this.