Download

Toggling Tick function causes crash?

Hello, So I looked around quite a bit to see if anyone had the same problem with toggling tick and tried some answers and tried different ways of toggling but nothing works so here is the code. also just as a side note It works when there’s nothing in Tick but as soon as I add some code then it crashes. Am I missing something??


AFirstPersonCharacter::AFirstPersonCharacter()
      :bInBuildMode{false}
{
    PrimaryActorTick.bCanEverTick = true;
}

void AFirstPersonCharacter::BeginPlay()
{
    Super::BeginPlay();
    SetActorTickEnabled(false);
}

void AFirstPersonCharacter::Tick(float DeltaTime)
{
    Super::Tick(DeltaTime);
    DrawDebugLine(
        GetWorld(),
        CameraComp->GetComponentLocation(),
        CameraComp->GetComponentLocation() * 250.0f,
        FColor::Purple,
        true,
        1.0f,
        0,
        5.0f);
}

void AFirstPersonCharacter::SwitchMode()
{
    !bInBuildMode ? bInBuildMode = true : bInBuildMode = false;
    SetActorTickEnabled(bInBuildMode);
}



If anyone knows why it’s like that I would be very appreciative to know.
Thanks again in advance.

Hard to say if you dont post the stack trace. Possibly CameraComp is null.

Thank you for the suggestion. Apparently I just logged it to make sure and it is for some reason. I don’t know that was weird anyways thank you again.
Cheers :smiley: