I am trying to move/rotate Directional Light from my Player Controller. This is what in my header:
UCLASS()
class ABaseBuildingGamePlayerController : public APlayerController
{
GENERATED_BODY()
...
...
protected:
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Settings|Camera")
ADirectionalLight* DirectionalLightSource = nullptr;
...
...
}
Then in my cpp file I added to one of functions (better place would be beginplay, but for testing it executes every tick):
if (IsValid(DirectionalLightSource)){
DirectionalLightSource->AddActorWorldRotation(FRotator(MovementScaled.X, MovementScaled.Y, 0));
} else {
TArray<AActor*> FoundLights;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), ADirectionalLight::StaticClass(), FoundLights);
if(GEngine)
GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("DirectionalLightSources found %f"), FoundLights.Num()));
for (AActor* TActor : FoundLights)
{
if (TActor->GetName().Equals("SunLight"))
{
DirectionalLightSource = Cast<ADirectionalLight>(FoundLights[0]);
break;
}
}
}
However, I got printed DirectionalLightSources found 0.000000
. Why I cannot get any DirectionalLight when there definitely one in outline?