Editor Keeps crashing cause of code

Everytime i build this code it crashes the editor and when i try to reopen it just crashes again.But when i comment the line of code and rebuild it works again.On SphereComponent->SetWorldLocation(SpotLightPicker->GetActorLocaiton()); when i comment that line of code the editor works again.

FloatMath_ScaleAndSphere = Scale * DefaultSphereRadius;

	USphereComponent* SphereComponent = CreateDefaultSubobject<USphereComponent>(TEXT("RootComponent"));
	RootComponent = SphereComponent;
	SphereComponent->SetSphereRadius(FloatMath_ScaleAndSphere);

	SphereComponent->SetWorldLocation(SpotLightPicker->GetActorLocation());

It seems that SpotLightPicker is not valid. Check if SpotLightPicker exist:

if(SpotLightPicker)
{
	SphereComponent->SetWorldLocation(SpotLightPicker->GetActorLocation());
}

it stops it from crashing but doesnt do want i wat it to do.And SpotLightPicker is a UPROPERTY.
But got the code to work just did a new function OnConstruction. Works now :smiley:
cpp:

void AVLDVisual::OnConstruction(const FTransform & Transform)
{

    FloatMath_ScaleAndSphere = RadiusScale * DefaultSphereRadius;

	SphereComponent->SetSphereRadius(FloatMath_ScaleAndSphere);

	SphereComponent->SetWorldLocation(SpotLightPicker->GetRootComponent()->GetComponentLocation());
}