UE4 c++ Delay/Timer syntax
Vložit
- čas přidán 11. 09. 2024
- How to set up the equivalent of a delay in c++ using the timer manager.
Copy paste syntax:
Declare timer handle:
FTimerHandle _loopTimerHandle;
Begin timer:
GetWorld()(point)GetTimerManager().SetTimer(_myTimerHandle, this, &AMyActor::MyFunctions, 5.f, false);
Note - using point as I can't use greater than or less than in description
Thank you man! Only after this video i understood how timer works
Thanks, that was very helpful.
Jonathan Lambert glad it helped!
The audio was bad but still very helpful! Thanks!
Yeah sorry about that, I only realized after I'd recorded a few of these that the recording program was set to use the inbuilt mic, not the headphone mic -.- But glad you found the content useful, thanks for taking the time to comment!
I got it to work your way, but I want to call the delay from another method. This method is called in blueprint through event tick. Basically its a simple if statement checking if im in range, then I want it to call a method that prints "Attack" every second. So I have the timer in that if statement and it never prints the message. I verified that I do in fact reach that part of the code.
Basically it seems like if I dont call it in BeingPlay() it never gets called.
I can't say for sure without seeing the code, but from the sounds of it it's not that it only works if called from OnBeginPlay() - it's that it won't work on tick because you're restarting the delay every single frame. You shouldn't really call delays from on tick - even in blueprint. If you have to do it that way, you should be able to get the state of the timer using the handle, there should be an 'IsTimerActive' or something along those lines you can check before re-calling it. But I'd have a look at your structure and see if that's where you should be calling the delay from.
thanks for the video :)
+kunal tomar You're very welcome! Glad you found it useful.
and ,why need two "settimer" functions in the different places?
+ue4gamedev That's just to make the loop, you don't need to have it in two separate places, but to fire off a loop on begin play, you use it to trigger the loop initially, then you use it again within itself to make that loop indefinitely.
+Matthew Hennegan Thanks for your answer.But I find other function in the documentation like "UPrimitiveComponent::BeginComponentOverlap( const FOverlapInfo & OtherOverlap, bool bDoNotifies)", but it seems to us that no useful,IF I want to deal with the collision ,the delegate is the only one way?
Sorry for bumping an old video, but this was probably the most helpful tutorial I could find so far...
So...I have a for loop within another for loop and i need the second one to have a delay on its end...so basically something like this:
for(int32 i=0; i
In short - i've never found a clean way to do it. You can't put a time delay inside a for loop, it breaks how the for loop is mean to work. You do have a do a hack around one way or another. You can do it with timers with the syntax in this video, or just manually make them yourself by counting time every 'on tick' with delta time and looking for if it's gone past the timer value, but either way you will need your own manual counters and just watch for when the 'loops' should cancel manually. I agree it is dirty, but I never found a clean way to do that either.
I see you just declare the FtimeHandle "_looptimerHandle",but you don not initialize it.how did it work?
+ue4gamedev It'll be being set up within the timer manager itself. You only need to declare it so that you can use it. Think of the timer handle as a tag for that specific timer, it lets you talk to the timer manager about that specific one.
make the font even smaller, you can...