#Why is StaticOptimizeEntity/static marked removing colliders for prefabs?

1 messages · Page 1 of 1 (latest)

midnight tundra
#

Why is StaticOptimizeEntity/static marked removing all the colliders from prefab? In the case of placing it in subscene it works fine.
In my case I want to spawn them each in their own simulation world and I don't want to set this up with different subscenes manually.

pallid knot
#

are you sure they are removed? the colliders are combined in the parent PhysicsBody i think.

#

And if you are on 1.0 the only way to convert to Entity Prefabs and spawn them is through subscenes right now.

midnight tundra
midnight tundra
#
public class SpawningDataAuthoring : MonoBehaviour
{
    public GameObject staticPrefab;
    public GameObject dynamicPrefab;
    public class Baker : Baker<SpawningDataAuthoring>
    {
        public override void Bake(SpawningDataAuthoring authoring)
        {
            AddComponent(new SpawningData()
            {
                staticPrefab = GetEntity(authoring.staticPrefab),
                dynamicPrefab = GetEntity(authoring.dynamicPrefab)
            });
        }
    }
}
midnight tundra
#

<bump>

midnight tundra
#

<bump>

sullen gyro
#

@midnight tundra : I have brought this up internally and we are looking into this as we speak.

#

If I understand your setup correctly, your prefab contains a "StaticOptimizeEntity" component, in which case the colliders are removed unexpectedly. If you remove this component, then the colliders function correctly. In the screenshot above, the right side shows the case without StaticOptimizeEntity component in which case the static box colliders appear. On the left is the case with the StaticOptimizeEntity in which case the static box colliders do not appear and the dynamic bodies fall through the brown box consequently.
Is my understanding correct?

midnight tundra
sullen gyro
#

Thanks for confirming. We will have a look at this and get back to you!

sullen gyro
#

Hi @midnight tundra ! I was able to reproduce this with your test project and am looking into the details right now.
Looking at your code, you will need to take a few things into account:

  1. When using StaticOptimizeEntity, only every top-level game object that contains a Physics Shape will yield an entity that holds a PhysicsCollider (compound collider with all the children's physics shapes in the corresponding sub-tree). The child entities do not hold a PhysicsCollider. You can see that when you throw a prefab directly into your scene and bake it. If you take a look at the Entity for the prefab gameobject itself, you will find the PhysicsCollider in the inspector, but not on its children. In your current code you are expecting a PhysicsCollider on every child entity which leads to exceptions.
  2. Adding a StaticOptimizeEntity component directly at the root works fine when dropping the prefab directly in the scene (situation as described above). When instantiating it as Entity though, the PhysicsCollider at the root does not get created. I am currently looking into the details of why that is, but my hunch is that you need an additional empty "parent" game object in your prefab that has the StaticOptimizeEntity component and that contains all the current top-level game objects (all with physics colliders) in your prefab. I am trying this out at the moment and will get back to you with more info.
#

Here you can see the scenario explained in (1) with an extra parent game object in the prefab that holds the StaticOptimizeEntity component:

#

In this case, none of the child game objects, each of which has a Physics Shape Authoring component, contains a Physics Collider as can be seen here:

midnight tundra
#

Right so if I add an PhysicsBody on the top parent it actually works.

sullen gyro
#

Yeah that's my guess.

#

Here is the same case but without the extra parent just for completeness' sake:

sullen gyro
#

@midnight tundra : I also just confirmed that by adding a top-level static Physics Body you get the desired behavior of an "optimized" single compound physics collider.
See here:

sullen gyro
#

Let me know if you need any further assistance in this case, or if that behavior is fine for your scenario.

midnight tundra