C++ script with TriggerBox

Good afternoon!

The situation is as follows: there are two corridors, which the player will pass in a circle during the experiment. At the place of each turn there is a TriggerBox. The task is as follows: during the activation of the button, enter a digit into the text file. If it is TriggerBox 1 - 1, if it is TriggerBox2 - 2. Maybe it is possible to implement this functionality using Blueprint? If not, can you please help me optimise the script, as I am still lacking knowledge, I am compiling a level for our cognitive experiments lab.

#include "YourCustomActor.h"
#include "Components/BoxComponent.h"
#include "Misc/Paths.h"
#include "Misc/FileHelper.h"

// Constructor  
AYourCustomActor::AYourCustomActor()
{
    // PrimaryActorTick
    PrimaryActorTick.bCanEverTick = true;

    // Create TriggerBox1
    TriggerBox1 = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox1"));
    TriggerBox1->SetBoxExtent(FVector(50.f, 50.f, 50.f));
    TriggerBox1->OnComponentBeginOverlap.AddDynamic(this, &AYourCustomActor::OnTriggerBox1Overlap);
    RootComponent = TriggerBox1;

    // Create TriggerBox2
    TriggerBox2 = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox2"));
    TriggerBox2->SetBoxExtent(FVector(50.f, 50.f, 50.f));
    TriggerBox2->OnComponentBeginOverlap.AddDynamic(this, &AYourCustomActor::OnTriggerBox2Overlap);
    TriggerBox2->SetupAttachment(RootComponent);
}

// Event handler for TriggerBox1 overlap
void AYourCustomActor::OnTriggerBox1Overlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
                                            UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
                                            bool bFromSweep, const FHitResult& SweepResult)
{
    // Write information to the text file
    WriteToLogFile(1);
}

// Event handler for TriggerBox2 overlap
void AYourCustomActor::OnTriggerBox2Overlap(UPrimitiveComponent* OverlappedComp, AActor* OtherActor,
                                            UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
                                            bool bFromSweep, const FHitResult& SweepResult)
{
    // Write information to the text file
    WriteToLogFile(2);
}

// Function to write information to the text file
void AYourCustomActor::WriteToLogFile(int32 Value)
{
    FString FilePath = FPaths::ProjectDir() + TEXT("TriggerLog.txt");

    // Open the file for writing
    IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
    IFileHandle* FileHandle = PlatformFile.OpenWrite(*FilePath);
    if (FileHandle)
    {
        // Convert the value to a string and write it to the file
        FString ValueStr = FString::Printf(TEXT("%d"), Value);
        FileHandle->Write((const uint8*)TCHAR_TO_UTF8(*ValueStr), ValueStr.Len());
        FileHandle->Write((const uint8*)"\n", 1);

        // Close the file
        delete FileHandle;
    }
}

Would be very appreciated for the help!