How to set attenuation of a light source in C++

I can’t find any possibility to adjust the attenuation in C++. There are methods to set brightness (probably means intensity), inner and out cone angles for spotlights but no attenuation setting.
Is this a planned addition? Is there a workaround (I’d be happy if I were just able to set a default value of 400 instead of 1000 without having to change it in the source code of UE).

Hey Mo,

There is a method SetAttenuationRadius in UPointLightComponent.h

Greetings

the function is private though

Yes you’re right.
Why the hell is a Setter private? >_>

Probably has to do with “GENERATED_UCLASS_BODY”. Should not it be simply “GENERATED_BODY” as of UE 4.12? I cannot get to the macro definition, but maybe the old one (GENERATED_UCLASS_BODY) defined the access as public before, but sets “private” now? Anyway, looks like they’ve forgotten about the function. Will repost it to the bug reports section.

Hey Mtimofeev,

I am able to use SetAttenuationRadius( ) just fine using 4.12.5. Can you show me in what context you are having an issue of not being able to access SetAttenuationRadius( ) on a UPointLightComponent?

Thanks.

Hello, yeah, I figured it out already, but thank you for your response!

The confusion arose from the two facts:

  1. neither ASpotLight nor APointLight has a getter for the Spot/PointLightComponent, so one has to address them as a property.
  2. SetAttenuationRadius() has no access modifier, hence the default visibility. I thought it’d be private or internal (as in .NET, c++, c#…)

But everything is cleared up now, thanks again.

If anybody stumbles upon this thread, it works like that:

APointLight* PointLight = Cast<APointLight>(World->SpawnActor(ASpotLight::StaticClass()));
PointLight->SetMobility(EComponentMobility::Movable);
PointLight->PointLightComponent->SetAttenuationRadius(300);

ASpotLight* SpotLight = Cast<ASpotLight>(World->SpawnActor(ASpotLight::StaticClass()));
SpotLight->SetMobility(EComponentMobility::Movable);
SpotLight->SpotLightComponent->SetAttenuationRadius(300);