Obi Official Forum
Help Adding ObiColider To Generated Mesh Is Slow - Printable Version

+- Obi Official Forum (https://obi.virtualmethodstudio.com/forum)
+-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html)
+--- Forum: Obi Rope (https://obi.virtualmethodstudio.com/forum/forum-4.html)
+--- Thread: Help Adding ObiColider To Generated Mesh Is Slow (/thread-4534.html)



Adding ObiColider To Generated Mesh Is Slow - aderae - 08-08-2025

Hello,

I am procedurally generating my world in 256x256 mesh chunks and whenever player is on one chunk, I am adding ObiCollider to it. However this blocks the main thread for a second and locks the game.

Is there a way to do this in Jobs system inside a thread?

Thanks!


RE: Adding ObiColider To Generated Mesh Is Slow - chenji - 08-08-2025

Hi,

I think yes, what's the problem? If the block-main-thread-time is caused by creation of new object I may pre-create some objects, save them in a pool (maybe 10 objects), when the scene is loaded, and use a thread to monitor&fill that pool until the object number reaches max value (10). When you need a new object in Update() or other place in main thread, just take it from the pool, instead of creating a new one.
Also check which collider you're using. Avoid using mesh collider.


RE: Adding ObiColider To Generated Mesh Is Slow - aderae - 08-08-2025

All the chunks have different mesh so I can't pool them together. It is a runtime generated infinite world so I cannot create everything during loading as well. I am using mesh colliders for world ground I know it is expensive but I need it to be like this for realism. I can already bake Mesh collider in a thread but the moment I add ObiCollider to it, since it is a big mesh it blocks the whole game for a second which is of course not ideal.


RE: Adding ObiColider To Generated Mesh Is Slow - josemendez - 08-08-2025

(08-08-2025, 11:25 AM)aderae Wrote: Hello,

I am procedurally generating my world in 256x256 mesh chunks and whenever player is on one chunk, I am adding ObiCollider to it. However this blocks the main thread for a second and locks the game.

Is there a way to do this in Jobs system inside a thread?

Thanks!

Hi!

Creating a MeshCollider involves building the spatial acceleration structure for it (bounding interval hierarchy, in Obi's case) which takes some time. This is currently done in the main thread.

The hierarchy is created in ObiTriangleMeshContainer.cs (by calling the BIH.Build() method) every time a new MeshCollider gets a ObiCollider component added to it. You could try modifying this file to use a job or a coroutine, in that case special care should be taken to make sure particles can't actually approach the collider before its creation is finished - otherwise they'll ignore it.

kind regards,


RE: Adding ObiColider To Generated Mesh Is Slow - aderae - 08-08-2025

(08-08-2025, 12:58 PM)josemendez Wrote: Hi!

Creating a MeshCollider involves building the spatial acceleration structure for it (bounding interval hierarchy, in Obi's case) which takes some time. This is currently done in the main thread.

The hierarchy is created in ObiTriangleMeshContainer.cs (by calling the BIH.Build() method) every time a new MeshCollider gets a ObiCollider component added to it. You could try modifying this file to use a job or a coroutine, in that case special care should be taken to make sure particles can't actually approach the collider before its creation is finished - otherwise they'll ignore it.

kind regards,

Thanks. I thought this would be the way to go but was just checking if you had something else I am missing.