Timer Binding

When I created the timer in game mode, I bound it.

void AToonTankGameMode::HandleGameStart()
{

    Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));

    ToonTanksPlayerController = Cast<AToonTanksPlayerController>(UGameplayStatics::GetPlayerController(this, 0));

    if (ToonTanksPlayerController)
    {
        ToonTanksPlayerController->SetPlayerEnabledState(false);


        FTimerHandle PlayerEnableTimerHandle;

        FTimerDelegate PlayerEnabledTimerDelegate = FTimerDelegate::CreateUObject(
            ToonTanksPlayerController, 
            &AToonTanksPlayerController::SetPlayerEnabledState, 
            true
        );
        GetWorldTimerManager().SetTimer(
            PlayerEnableTimerHandle, 
            PlayerEnabledTimerDelegate, 
            StartDelay, 
            false
        );
    }
}

But when I used SetTimer in Tower, I don’t think I bound it.

void ATower::BeginPlay()
{
    Super::BeginPlay();

    Tank = Cast<ATank>(UGameplayStatics::GetPlayerPawn(this, 0));

    GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::CheckFireCondition, FireRate, true);
}

I do binding in game mode, but don’t I do binding in Tower? :persevere:

You are binding it. The method is ATower::CheckFireCondition

But I think I used Deligate in Game Mode, but I don’t think Tower used it.

Or is it used and I don’t know?

It has to use the one in the tower class as the class name ps specified. It cannot use the game mode because it is inside a different class.If you want to be sure, add a debug statement and each with the delegate name and you’ll see which is being called.

What do you mean? I didn’t understand

Sorry for the confusion. When you bind to a method, one way is to add the method name as a parameter in set timer. You’ve done this. The other way you’ve shown uses a delegate which enables external classes to bind to that delegate too and so when the timer triggers, it will call the bound functions.

Both are different methods of doing the same thing. Both are set up correctly.

If you are u sure, look at the end of lecture code and compare with what you have.

So, the binding methods were different for Tower and Game Mode.

Then, does Tower work the same way even if I create it like a Game Mode code?

It should but the method in the gamemode is different and needs to be able to add external calls. The tower is local to the tower so it is different use cases.

I understand what you mean! Thank you.

After the project I’m currently learning is completed, can I ask this community if there’s anything I don’t know while developing additionally?

There’s lots, assuming you are new to unreal. This is a beginners course so it covers a lot but it is just a taster really.

Off the top of my head, there’s more comprehensive input systems, advanced character AI, multiplayer (I always say 2 years of C++ in industry and at least 1 year of UE experience before going near that) compositing, VR/AR, mobile, materials, cinematics, Paper2D which is so fun and the list goes on. Then there’s the non specific unreal stuff like sound design, level design, music and pairing it with your designs, game design in general, 3D modelling, 2d artwork for 2d games or UI and again the list goes on.

Mostly practice is what I would recommend. Extend course projects and add your own unique feature to it make your own, be it via level design, new models, or simple things.

Game development is not difficult but depends on a wide range of skills to be good at it.

Good luck

Thank you for the nice words.

by any chance
image
In the lecture, it shows what parameters to put in parentheses, but I don’t.
Is there a way to make it float?

No, spawn emitter is spawning a particle system.

My words seem to have caused confusion.


That’s how the lecture tells you what to put in the parameters. But it doesn’t come out with my vs code.

So, the 3 parameters you need are the world, so GetWorld(), the Particle system and lastly an FTransform which contains position, rotation and scale

So, the call would look like
UGameplayStatic::SpawnEmitterAtLocation(GetWorld(), Emitter, Transform);

The Emitter is probably added via a UPROPERTY(EditAnywhere)

To expand on the original question.

GetWorldTimerManager().SetTimer(FireRateTimerHandle, this, &ATower::CheckFireCondition, FireRate, true);

This overload of SetTimer creates the delegate for you as a convenience. It’s the same as doing what you did for the other i.e.

FTimerDelegate FireDelegate = FTimerDelegate::CreateUObject(
    this, 
    &ATower::CheckFireCondition);

GetWorldTimerManager().SetTimer(FireRateTimerHandle, FireDelegate, FireRate, true);

The code in Unreal for that overload:

thank you!

thank you!!

Privacy & Terms