Download

How to convert Do once ,setTimer , play sound attached to c++ code?

1.jpg

Hello! EveryOne, I hope anyone can help me I will appreciated.

hello,

for do once you can make two function like this :

In your .h file:


	bool bDo;

	void MyDoOnce();

	void ResetMyDoOnce();

In your .cpp file, don’t forget to initialize bDo :


void YourClass::MyDoOnce()
{
	if (bDo)
	{
		//Do something
		return;
	}
	else
		return;
}

void YourClass::ResetMyDoOnce()
{
	bDo = true;
	return;
}


}

for Timer :

In your .h file :


FTimerHandel MyTimer;

In you .cpp file :


GetWorldTimerManager().SetTimer(MyTimer, this, &YourClass::YourFunction,2.f /*Time you want*/, false /*if you want loop set to true*/);

GetWorldTimerManager().ClearTimer(MyTimer);

for sound:


UGameplayStatics::PlaySoundAttached(SoundToPlay, MyPawn->GetRootComponent()/*Location*/);

BTW you can right-click a node and hit ‘GoTo Code Definition’ and it’ll take you to that node in C++ :slight_smile: