RealityKit components removed on GameObject deactivation

While tracking down performance issues, I’ve noticed that when PolySpatial deactivates an Entity due to its GameObject being deactivated, it also removes the entity’s components. The components are then recreated again when the entity is reactivated.

I imagine this is so that changes to deactivated GameObjects do not need to be synchronized each frame.

While this isn’t generally a huge issue as adding components is pretty fast, for BoxCollider this causes the ShapeResource to get recreated, which then blocks the main thread for a frame (or longer) due to the synchronous asset creation.

The deactivation behaviour means that I can’t workaround the expensive ShapeResource construction by pooling colliders, as when the collider enters the pool (and is deactivated) it loses its ShapeResource.

I’m currently working around this case successfully by switching the BoxCollider to a MeshCollider with a shared mesh; however there are possibly other scenarios that cannot be solved this way (for example, sphere and capsule colliders could only be approximated with a mesh, so might not be suitable for all use cases). There may be other components with expensive creation costs as well.

Hi,

Could you file a bug, and optionally attach a repro project if time permits? I’ll raise it internally in the team as well, there are indeed other components that have expensive creation costs on disable/enable, and we could possibly apply whatever we do with collider components to those other components.

Thanks, I’ve submitted IN-59917