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

**URL:** <https://forums.unrealengine.com/t/is-is-safe-to-call-trace-methods-from-another-thread/127950>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [June 24, 2019, 5:39pm UTC](https://forums.unrealengine.com/t/is-is-safe-to-call-trace-methods-from-another-thread/127950 "2019-06-24T17:39:53Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![IrSoil](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@IrSoil](https://forums.unrealengine.com/u/IrSoil)\
**Post date:** [December 26, 2024, 2:03pm UTC](https://forums.unrealengine.com/t/is-is-safe-to-call-trace-methods-from-another-thread/127950/6 "2024-12-26T14:03:11Z")

</div>

While i’m still looking for answer, it’s worth mention that this suggestion doesn’t seems correct now. I’m on 5.3 and `UWorld::AsyncLineTraceByChannel` calls the `StartNewTrace` that has a guard against threading at the very begining:

```c++
		// Using async traces outside of the game thread can cause memory corruption
		check(IsInGameThread());

```

upd:  
`ActiveSound.cpp` Have an interesting comment at the line 1220

```c++
				if (UWorld* WorldPtr = World.Get())
				{
					// LineTraceTestByChannel is generally threadsafe, but there is a very narrow race condition here
					// if World goes invalid before the scene lock and queries begin.
					bIsOccluded = WorldPtr->LineTraceTestByChannel(SoundLocation, ListenerLocation, OcclusionTraceChannel, Params);
				}

```

So it seems default traces is a way to go now. At least they seems to work at the first glance.  
Also there is a topic with an engine fix that seems relevant to the problem, but i’m don’t need it yet.

> [@How to do scene sweeps/traces on the async physics thread?](https://forums.unrealengine.com/t/how-to-do-scene-sweeps-traces-on-the-async-physics-thread/607030/2):
>
> Found two solutions, posting here so others can do the same. Basically the problem is in the function GetThreadQueryContext() in SceneQuery.cpp. On line 330 it says “//TODO: need a way to know we are on a physics thread task (this isn’t supported yet)”. Solution one is to replace the line below that comment with the following: if (IsInGameThread()) { return EThreadQueryContext::GTData; } else { return EThreadQueryContext::PTOnlyData; } The above assumes that any other thread th…

---

_[View the full topic](https://forums.unrealengine.com/t/is-is-safe-to-call-trace-methods-from-another-thread/127950)._
