Announcement

Collapse
No announcement yet.

Someone please help, I don't know why the engine kept on crashing after trying to use timers

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Someone please help, I don't know why the engine kept on crashing after trying to use timers

    So this is my codes


    .cpp
    // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.


    #include "ALevelGameMode.h"

    #include "ALevelCharacter.h"

    #include "UObject/ConstructorHelpers.h"

    #include "Engine/World.h"


    AALevelGameMode::AALevelGameMode()

    {

    // set default pawn class to our Blueprinted character

    static ConstructorHelpers::FClassFinder<APawn> PlayerPawnBPClass(TEXT("/Game/SideScrollerCPP/Blueprints/SideScrollerCharacter"));

    if (PlayerPawnBPClass.Class != NULL)

    {

    DefaultPawnClass = PlayerPawnBPClass.Class;

    }


    // Begin

    UE_LOG(LogTemp, Warning, TEXT("GAME START"));

    //TimerLoop();


    }


    /*void AALevelGameMode::TimerLoop()

    {

    if(IsTimerOn)

    {

    GetWorld()->GetTimerManager().SetTimer(TimerHandle, this, &AALevelGameMode::SendPulse, TimerDelay, true, 1.f);

    }

    }*/


    void AALevelGameMode::SendPulse()

    {

    SendSignal.Broadcast(true);

    SendSignal.Broadcast(false);

    UE_LOG(LogTemp, Warning, TEXT("bruh moment"));

    }

    .h


    // Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.


    #pragma once


    #include "CoreMinimal.h"

    #include "GameFramework/GameModeBase.h"

    #include "Engine/World.h"

    #include "Engine/Public/TimerManager.h"

    #include "ALevelGameMode.generated.h"



    // Declare a delegate for synchronizing the cells

    DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FSend, bool, Pulse);


    UCLASS(minimalapi)

    class AALevelGameMode : public AGameModeBase

    {

    GENERATED_BODY()


    public:

    AALevelGameMode();


    // part of delegate for synchronizing

    UPROPERTY(BlueprintAssignable)

    FSend SendSignal;


    // timer

    //void TimerLoop();


    UFUNCTION()

    void SendPulse();


    bool IsTimerOn = true;


    float TimerDelay = 1.f;


    FTimerHandle TimerHandle;


    };


    I have absolutely no idea why is this happening



    #2
    Use your timer in or after BeginPlay() instead. GetWorld is not usually ready for use in constructors.
    SolidGasGames

    Comment

    Working...
    X