How do I do a Delay in C++?

Hey!
I have tried timers already, but somehow it doesn’t work for me.
I want to make a blinking light. I already have it working in BP, but I like to move everything to C++ when I have it working in BP.

This is how it looks in BP:

http://www.fotos-hochladen.net/uploads/blinkinglightsi75fkx1mz.png

And my C++ solution:

void AFlickeringLight::Delay()
{
GetWorldTimerManager().SetTimer(this, &AFlickeringLight::Flicker, 0.3f, true);
}

I asked on a forum if that is right and they said it is. Why doesn’t it work?

Where should I call it? I tried Tick, but I think that is not right.

Do you want it to happen the entire time the object is alive? I’d probably call it in the PostInitializeComponents() function of your Actor. Calling it in Tick will I believe reset the timer every time it’s called. The Blueprint node does extra work to allow you to use it in a Tick to prevent it from stomping the current delay.

Thanks, I’ll try it.
I will tell you if it worked when I tried it :slight_smile:

How exactly do I call PostInitializeComponents?

I tried: “void AActor::PostInitialiveComponents() {Delay();}” but that gave me “inconsistent dll linking”

I also tried:

void AFlickeringLightBrightness::PostInitializeComponents()
{
	Super::PostInitializeComponents();
        Delay();

}

With virtual void PostInitializeComponents() OVERRIDE; in the Header File

So the issue is related to the DLL exported nature of the class I think you’ve decided to use as your base class. I’m guessing you’re using a APointLight as your base class?

it’s defined thusly,

class APointLight : public ALight

Compare to AActor, which is full exported from the DLL. Long story short, make sure you’re not using those Wrapper Classes, they’re practically deprecated.

Use AActor as your base class, and add a UPointLightComponent that you can control. Also begin the timer in BeginPlay, that is probably the more acceptable location for it.

Cheers,
Nick

Yeah… I put it in BeginPlay now and it works ^^