So, just to clarify, here is what i’ve done. This should be your setup:
Header File:
#pragma once
#include "GameFramework/Actor.h"
#include "MySkySphereClass.generated.h"
/**
*
*/
UCLASS()
class PLAYGROUND_API AMySkySphereClass : public AActor
{
GENERATED_UCLASS_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SkySphereTest")
ADirectionalLight* MyTestDirectionalLight;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "SkySphereTest")
FRotator MyTestRotator;
virtual void BeginPlay() override;
};
C++ File:
#include "Playground.h"
#include "MySkySphereClass.h"
AMySkySphereClass::AMySkySphereClass(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
}
void AMySkySphereClass::BeginPlay()
{
Super::BeginPlay();
if (MyTestDirectionalLight)
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(0, 60.0F, FColor::Black, TEXT("It's not NULL"));
}
MyTestRotator = MyTestDirectionalLight->GetActorRotation();
MyTestRotator.Pitch += 200;
MyTestDirectionalLight->SetActorRotation(MyTestRotator);
}
else
{
if (GEngine)
{
GEngine->AddOnScreenDebugMessage(1, 60.0F, FColor::Black, TEXT("It's NULL"));
}
}
}
This works, since BeginPlay is called after the pointer is filled. If you would place the code into the Constructer, it wouldn’t work, because this would be called with the pointer being NULL. You would need to set the pointer in the constructor instead of the scene outliner.
You don’t need the MyTestRotator variable like i did. That was just for debugging etc.