LineTraceSingle performance for small subset of complex scene.

I have compex scene - landscape, lot of meshes, physical collisions.

I would like to use additional LineTrace against an narrow set of simple meshes (with simple collisions) - those objects are static (non moveable).

I figured out that performance of LineTraceSingleByObjectType is related rather to overall scene complexity, and do not improves when LineTrace is limited to specific collision channel.
Even when I AddObjectTypesToQuery only channel that has no object on scene - performance is still poor.

I can understand there is an scene-wide BVH tree that includes all the geometry, and every trace has to go thru whole BVH tree to hit something, and just in the end there is condition that checks is the hit object one of my channels of interest.
And that explains why LineTrace performance is related to scene complexity.

But is there an way to improve performance of LineTrace for small subset of meshes?
Like to preparte separate BVH tree with only those objects, and be able to do faster trace here?

Duplicating whole UWorld seems to be overkill, but maybe there is something else possible?

I tried also to set “No collision” for other objects.
It is not an solution for me, because it impacts also physical collision that I would like to have enabled.
But funny thing is that do not help for LineTrace performance. So it looks like condition “is collision enabled” is checked only when collision is detected, but not during BVH calculation (I guess because devs want to be able to quicky turn on and off collision).

Maybe some other out of the box ideas? :slight_smile:

There is a function that can trace against specific components only - LineTraceComponent. Since you’re dealing with a complex scene (and a long trace?), looping though a subset of static mesh components might be faster in this very instance which, I must admit, is somewhat unorthodox since line tracing is pretty efficient. Would it make sense?

Thank you, I’ll try and check performance.

It may be really good idea for my purpose.

I do need this traces majority of the time, but when I need from time to time - I need lot of rays at each frame to do such “scan” - but still limited to one, maybe few near components.

1 Like