# Are interface calls thread safe

**URL:** <https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082>\
**Category:** UI\
**Tags:** garbage-collector, interfaces, unreal-engine, question\
**Created:** [June 10, 2018, 4:18pm UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082 "2018-06-10T16:18:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff0ebfa4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff0ebfa4](https://forums.unrealengine.com/u/anonymous_user_ff0ebfa4)\
**Post date:** [June 10, 2018, 4:18pm UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082/1 "2018-06-10T16:18:37Z")

</div>

Dear community, I have a strange problem with interfaces.  
My async task does some interface calls in loop via Execute\_… method. And at that moment when GC starts, next call throws assertion !IsUnreachable() on calling object, leading to engine crash. But this is only the case, i.e. if i do these calls in game thread or do async call the normal method of the same object in same conditions, everything happens ok. Experiments around this showed, that when I pause my custom thread to allow GC accomplish its work and then run it again, everything happens ok and no objects are destructed. In what may be the reason for this? The only idea i have for now is some problems with thread safety of interface calls.

---

<div class="post-metadata">

**Author:** ![ZeroParadigm](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ZeroParadigm](https://forums.unrealengine.com/u/ZeroParadigm)\
**Post date:** [June 11, 2018, 10:37pm UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082/2 "2018-06-11T22:37:56Z")

</div>

Are you able to hold a strong reference to the object in question and wrap any code that uses it in IsPendingKill (IsKillPending?)

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [June 12, 2018, 4:23am UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082/3 "2018-06-12T04:23:09Z")

</div>

No, it isn’t safe in large majority of cases.  
What you can do from your Execute() is invoke a static function within GameThread from your AsyncTask which then executes UInterface calls for you, something like this:

```
DECLARE_CYCLE_STAT(TEXT("FSimpleDelegateGraphTask.MyTask"),STAT_FSimpleDelegateGraphTask_MyTask,STATGROUP_TaskGraphTasks);

```

* * *

```
if (IsInGameThread()) {
	MyStaticFunc(SomeParam);
} else {
	FSimpleDelegateGraphTask::CreateAndDispatchWhenReady(
		FSimpleDelegateGraphTask::FDelegate::CreateStatic(&MyStaticFunc,SomeParam),
		GET_STATID(STAT_FSimpleDelegateGraphTask_MyTask),
		nullptr,
		ENamedThreads::GameThread
	);
}

```

* * *

```
static void MyStaticFunc(USomeType* SomeInputParam) {
    // call interface functions here...
}
```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_ff0ebfa4](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_ff0ebfa4](https://forums.unrealengine.com/u/anonymous_user_ff0ebfa4)\
**Post date:** [June 15, 2018, 7:56pm UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082/4 "2018-06-15T19:56:15Z")

</div>

Thank you, BrUnO. I’ll try this as soon as possible.

---

<div class="post-metadata">

**Author:** ![Sn\_a\_ke](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Sn\_a\_ke](https://forums.unrealengine.com/u/Sn_a_ke)\
**Post date:** [August 21, 2019, 11:33am UTC](https://forums.unrealengine.com/t/are-interface-calls-thread-safe/427082/5 "2019-08-21T11:33:33Z")

</div>

I would like to raise this issue,  
sometimes when calling the interface, the object does not pass the “! IsUnreachable ()” check.  
Is there a safe way to call an interface ???

the function is a constant getter.  
my architecture does not allow me to wait until a delegate is called in the main thread and sends data back.

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/2/9/7298846d1bbd96e58428f281eb8c11b8c78d9ebc.png)

UE\_4.20\Engine\Source\Runtime\CoreUObject\Private\UObject\ScriptCore.cpp

 ![](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/2/5/825e82a420019c4453df8fc0458a2f62ff534e85.png)
