I have tried several way to create PointLight use C++, but they all don’t work.
1,
APointLight* PL = NewObject<APointLight>();
if (PL)
{
PL->AttachToActor(SelectedHero, FAttachmentTransformRules::KeepRelativeTransform);
//FVector Loc = SelectedHero->GetActorLocation();// FRotator(90.f, 0.f, 0.f).Vector() * 1000.f;
PL->SetActorRelativeLocation(FVector(0.f, 0.f, 1000.f));
ULightComponent* LC = PL->GetLightComponent();
if (LC)
{
LC->SetCastShadows(false);
LC->InverseSquaredFalloff_DEPRECATED = false;
LC->SetIntensity(20000.f);
LC->SetLightColor(FLinearColor(199, 125, 108));
PL->PointLightComponent->AttenuationRadius = 10000.f;
}
}
2,
UPointLightComponent* PLC = NewObject<UPointLightComponent>();
//GetWorld()->SpawnActor<UPointLightComponent>(UPointLightComponent::StaticClass(), Loc, FRotator(0.f, 0.f, 0.f));
//PLC->AttachTo(SelectedHero->GetMesh());
//PLC->RegisterComponent();
PLC->SetWorldLocation(FVector(1200.f, 1200.f, 500.f));
//PLC->SetRelativeLocation(FVector(0.f, 0.f, 1200.f));
PLC->SetCastShadows(false);
PLC->bUseInverseSquaredFalloff = false;
PLC->SetIntensity(20000.f);
PLC->SetLightColor(FLinearColor(199, 125, 108));
PLC->SetAttenuationRadius(10000.f);
How to achieve this?