# FPlatformProcess::Sleep crash in thread - bad thread use ? (flicker effect on damage)

**URL:** <https://forums.unrealengine.com/t/fplatformprocess-sleep-crash-in-thread-bad-thread-use-flicker-effect-on-damage/93260>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [May 29, 2017, 11:15pm UTC](https://forums.unrealengine.com/t/fplatformprocess-sleep-crash-in-thread-bad-thread-use-flicker-effect-on-damage/93260 "2017-05-29T23:15:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_b709974b](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_b709974b](https://forums.unrealengine.com/u/anonymous_user_b709974b)\
**Post date:** [May 29, 2017, 11:15pm UTC](https://forums.unrealengine.com/t/fplatformprocess-sleep-crash-in-thread-bad-thread-use-flicker-effect-on-damage/93260/1 "2017-05-29T23:15:16Z")

</div>

Hi,

I call a function called

```auto

twinkleDamage

```

when my enemy is touched.

I tried many different AsyncTask(ENamedThreads::XXX)  
and it seems that more prioritized is the thread, the more the game freeze when the thread is called.

VisualStudio break point when FPlatformProcess::Sleep is called

```auto

void AMyBasicMob::twinkleDamage()
{

		AsyncTask(ENamedThreads::AnyBackgroundHiPriTask , [this]() // GAMETHREAD ???
		{

			int i = 0;
			bool val = false;
			auto _mesh = this->GetMesh();
			if (_mesh) {
				while (i < 14) {
					UE_LOG(LogClass, Warning, TEXT("FLICKER LOOP"));

					if (!val) {
						_mesh->SetMaterial(0, FlikkerMaterial);
					}
					else {
						_mesh->SetMaterial(0, BaseMaterial);
					}

                                       // HERE ISSUE
                                       // trigger breakpoint or crash
					FPlatformProcess::Sleep(0.03);
                                        ////////////////
                                       ///////////
					val = !val;
					i++;
				}
				_mesh->SetMaterial(0, BaseMaterial);
				this->hitable = true;

			}
		});
	
}

```

As you probably guest, I’m a newbie in UE4, but I’ve done many c++ projects by the past,  
So somebody can tell me what’s wrong here?

Or If you have a best practice for thread that handle visual modification of actor, let me know!

thanks 🙂

---

<div class="post-metadata">

**Author:** ![eyosido](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@eyosido](https://forums.unrealengine.com/u/eyosido)\
**Post date:** [June 9, 2017, 1:07pm UTC](https://forums.unrealengine.com/t/fplatformprocess-sleep-crash-in-thread-bad-thread-use-flicker-effect-on-damage/93260/2 "2017-06-09T13:07:21Z")

</div>

> **[A new, community-hosted Unreal Engine Wiki](https://forums.unrealengine.com/t/a-new-community-hosted-unreal-engine-wiki/141494)**
>
> After over a year in maintenance mode, the official Unreal Engine Wiki is now permanently offline. These resources now live on a new community-run Unreal Engine Community Wiki — ue4community.wiki! You will be able to find content from the official...

It is likely the calls you are making from inside the thread are not meant to be made outside of the game thread. I am not even sure logging is safe from a non-game thread! Safest position I think is not to make any engine call from a non-game thread, only handle logic there then send messages to the game thread so code there can actually call the engine. However if an UE expert could elaborate on this I would also be interested.
