I think your object iterator is causing a problem, you can try this code :
This code is in the BeginPlay
TArray<AActor*> FoundLights;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ADirectionalLight::StaticClass(), FoundLights);
for (AActor* TActor : FoundLights)
{
if (TActor->GetName().Equals("SunLight"))
{
MySunLight = Cast<ADirectionalLight>(FoundLights[0]);
break;
}
}
and this one in your tick :
if (IsValid(MySunLight))
{
FRotator MyCurrentRot = MySunLight->GetActorRotation();
MySunLight->SetActorRelativeRotation(CurrentSunRotation);
}