UE4 c++ Delay/Timer syntax

Sdílet
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

Komentáře • 17

  • @adiladilov8655
    @adiladilov8655 Před 2 lety

    Thank you man! Only after this video i understood how timer works

  • @Jonathanlambert-art
    @Jonathanlambert-art Před 8 lety +4

    Thanks, that was very helpful.

  • @chicoSemCerebro
    @chicoSemCerebro Před 7 lety +7

    The audio was bad but still very helpful! Thanks!

    • @matthewhennegan839
      @matthewhennegan839  Před 7 lety +2

      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!

  • @rafikrizik4722
    @rafikrizik4722 Před 7 lety +2

    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.

    • @matthewhennegan839
      @matthewhennegan839  Před 7 lety

      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.

  • @kunaltomar131289
    @kunaltomar131289 Před 8 lety

    thanks for the video :)

  • @ue4gamedev960
    @ue4gamedev960 Před 8 lety +1

    and ,why need two "settimer" functions in the different places?

    • @matthewhennegan839
      @matthewhennegan839  Před 8 lety

      +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.

    • @ue4gamedev960
      @ue4gamedev960 Před 8 lety

      +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?

  • @the_dark_jumper2211
    @the_dark_jumper2211 Před 6 lety

    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

    • @matthewhennegan839
      @matthewhennegan839  Před 6 lety

      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.

  • @ue4gamedev960
    @ue4gamedev960 Před 8 lety

    I see you just declare the FtimeHandle "_looptimerHandle",but you don not initialize it.how did it work?

    • @matthewhennegan839
      @matthewhennegan839  Před 8 lety

      +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.

  • @user-mo8kc6vn9y
    @user-mo8kc6vn9y Před 3 lety

    make the font even smaller, you can...