Open Zyzyl opened 8 months ago
I haven't looked into this in depth yet so following is just stuff that I can think of the top of my head.
Is scaling part of the moving at all, even through part of the hierarchy (e.g. small scale being applied somewhere)? The Resonite 3D logo example sounds like it might be, if it's the one that "squishes".
I don't fully remember how it's implemented, but I think there might be mechanism that recalculates the convex hull when it is scaled is what's making it more expensive.
I'd also note, that the cost of the colliders that is mentioned is for actual collisions - moving them externally is something that's outside of the actual physics behavior. However the cost generally shouldn't differ between different types of colliders given same conditions, so something is definitely odd.
Another question here would be - how does this compare against sphere or box colliders exactly? Are those cheaper than convex hulls in this same test?
MeshColliders are a bit "special" and excluded from certain interactions, which could be accounting for the difference here too. E.g. when convex hulls & primitives get moved, they have additional checks based on the type, while mesh colliders will have fewer.
I'll have to have a look into this at some point to understand if it's is normal or not though, but those are questions that pop into my head.
I also thought about scaling at first, but I think we can exclude that. I went through the Resonite logo replication but additionally reset all positions, rotations and scales throughout the hierarchy. The only transform being driven was the position of the top level slot by a Panner3D. The ConvexHullColliders still resulted in a much higher PhysicsMoved frametime compared with either MeshColliders or similarly sized BoxColliders (which behaved very similarly). The latter result suggests this is not a MeshCollider vs. everything else difference either.
Describe the bug?
Some meshes cost much more performance than expected when referenced by a ConvexHullCollider component under a moving hierarchy. In my testing, the ConvexHullCollider can be >20x more expensive than a MeshCollider in this context. Primitive colliders are equal to or less expensive than MeshColliders, as expected.
Note, that while the performance impact of colliders under moving hierarchies is somewhat affected by the ColliderType enum, the performance difference between ConvexHullColliders and others is largely unaffected.
The performance cost of moving ConvexHullColliders seems to scale non-linearly with the vertex count of the referenced mesh (tested using IcoSphere meshes with differing levels of subdivisions). Cost seems to increase rapidly up to about 4 subdivisions and much more slowly after that.
Reporting this as a bug given that ConvexHullColliders are typically recommended as more efficient alternatives to MeshColliders. Nonetheless, if this is actually expected behaviour, it would be useful to know for documentation purposes.
To Reproduce
I have also saved an item which allows comparison of various different primitive mesh types and collider types in this folder:
resrec:///U-Zyzyl/R-EBFA7D6B59FA1EEA7363CC3C9A052E264F6E31F2C71195405AC19AB81783ED63
See the section below for a video demonstration using the item in the folder.
Expected behavior
The general understanding is that ConvexHullColliders are substantially more efficient than MeshColliders. Therefore I would not expect them to have greater performance costs than comparable MeshColliders when moved.
Screenshots
See this video for a demonstration: https://www.youtube.com/watch?v=1euQCGG8UtI
Resonite Version Number
2024.3.1.1178
What Platforms does this occur on?
Windows
What headset if any do you use?
HP Reverb G2, Desktop mode
Log Files
Log file corresponding to the reproduction video above: DESKTOP-SIS8AVA - 2024.3.1.1178 - 2024-03-02 16_44_40.log
Additional Context
I'll note that for the primitive mesh shapes I tested it would obviously make more sense to use a suitable primitive collider most of the time. I include the Resonite 3D logo example in the replication to show that this is an issue which could reasonably be encountered by users who are behaving according to generally understood collider best practices.
Reporters
Zyzyl (zyzylian on Discord)