Search Unity

Question How to wait for colliders to be ready

Discussion in 'Physics for ECS' started by mvysinsky, Jan 24, 2021.

  1. mvysinsky

    mvysinsky

    Joined:
    Mar 26, 2017
    Posts:
    3
    Hi,

    this is the result:


    No matter how long I wait before moving when I start a built game. I always fall through the first cube. After scene reloads, everything is fine. It is like physics is not properly initialised on first run (the cube has physics shape). Is there a way how to wait for it to be ready or detect when it is ready, please?

    This bug is not happening in the editor so it is hard to debug.
     
  2. Thygrrr

    Thygrrr

    Joined:
    Sep 23, 2013
    Posts:
    700
    This may be related with a bug I see with the physics world not updating the static collision world correctly upon load.

    Try this: A few frames after loading, create or delete a static collider programmatically. (e.g. spawn a prefab instance, or destroy a specifically marked one, no need to faff with colliders themselves).

    That usually triggers the Static Body Change filter. I see this corruption when I add static bodies right in the first frame or so; and the collisionworld array then isn't big enough to hold all the colliders (or is never updated, not sure)
     
    jasons-novaleaf likes this.
  3. milos85miki

    milos85miki

    Joined:
    Nov 29, 2019
    Posts:
    197
    Hi @mvysinsky ,

    Could you please provide a bit more details:
    1. Did you ensure that all Entity creation and editing jobs are completed before BuildPhysicsWorld.onUpdate starts or after ExportPhysicsWorld's last job ends?
    2. How are you creating those cubes with PhysicsShape and are you changing them afterwards?
    3. Did you manage to debug a bit, does BuildPhysicsWorld properly detect those cubes as physics bodies?

    The problem Thygrrr found (thank you!) happens when you remove some component from a number of entities representing static bodies, so I'd like this to be investigated before concluding anything. A project with minimal repro scene would be useful, but answering my questions above might also lead us to the solution.