Download

Is is safe to call "trace" methods from another thread?

Is it safe to call trace functions, like OverlapMultiByObjectType, from another thread (not the game thread)?
I’ve put my traces in an AsyncTask and the speedup is pretty awesome, but is that safe or I’m just being lucky?

No, you have to use the AsyncPhysics interface, for example “UWorld::AsyncLineTraceByChannel()”:

Could you please explain a little bit? I looked in the source and it seems it’s a FPhysicsInterface call executed inside an async task plus some threadsafe communication.

They return safe struct copy containing data from the alien thread.
Normal functions might return pointers to world elements or delegates and so they run in game thread.

You mean the normal function, like OverlapMultiByObjectType, can return pointers to Components that are not in the same World? I do many traces but only return one component back to the game thread.

edit: i mean, I just give some actors to the task, do some traces and calculation in the task, then give back a component. They are all supposed to be in the same world. So, if the communication between threads is okay, the trace itself is is tread-safe?

Let’s say the task and the game thread are not communicating, the task runs traces and print numbers on the log. Is that safe?