Setting Cone Angles On SpotLight

Hi, i’m trying to create some spotlights for a game i’m creating but i’m having some trouble setting the spotlights cone values when i’m trying to create them.

I get this error when i try to compile my code

Error 1 error LNK2019: unresolved external symbol "public: void __cdecl ASpotLight::SetOuterConeAngle(float)" (?SetOuterConeAngle@ASpotLight@@QEAAXM@Z) referenced in function "public: virtual void __cdecl ALightOrigin::BeginPlay(void)" (?BeginPlay@ALightOrigin@@UEAAXXZ) C:\Users\Joar Hedvall\Documents\Unreal Projects\Temple\Intermediate\ProjectFiles\LightOrigin.cpp.obj

But if i remove the part where is set the cone angle, i can compile and run with no issues.

This is my light creating code currently.

In Header
UPROPERTY(VisibleAnywhere, Category = "Switch Properties")
TArray<ASpotLight*> SpotLights;

In cpp
void ALightOrigin::BeginPlay()
{
	Super::BeginPlay();

	for (int i = 0; i < ReflectionCountMax; i++)
	{
		if (GWorld && SpawnLight)
		{
			ASpotLight* SpotLightTemp;
			SpotLightTemp = GWorld->SpawnActor<ASpotLight>(ASpotLight::StaticClass(), GetActorLocation(), GetActorRotation());
			SpotLightTemp->SetBrightness(Brightness);
			SpotLightTemp->SetEnabled(true);
			SpotLightTemp->SetOuterConeAngle(2.0f);
			SpotLights.Add(SpotLightTemp);
		}
	}
}

Am i doing something wrong when i’m creating the lights or are you not supposed to set the cone values at that point and if so, where do i set their values.

// Thanks

Did you ever find a solution to this?

I guessed “Light->SpotLightComponent->SetOuterConeAngle(5.0);”, which compiled, but didn’t actually change the outer cone angle from its default value of 44 or whatever.

I know this is an old inquiry, but I have an answer and would like to provide it if someone else (like me) stumbles upon this post.

The linker error is due to SetOuterConeAngle() (and SetInnerConeAngle() for that matter), have been marked as deprecated when trying to call it directly from the ASpotlight object. The documentation: “BEGIN DEPRECATED (use component functions now in level script)”. The guess that was made for the fix of:

Light->SpotLightComponent->SetOuterConeAngle(5.0);

will actually work. However, in order for it to actually work, you need to make sure the light is considered “movable” – if it’s not set to this, then attempting to make the change via the methods will have no effect. The code for SetOuterConeAngle() looks like this:

void USpotLightComponent::SetOuterConeAngle(float NewOuterConeAngle)
{
   if (AreDynamicDataChangesAllowed(false) && 
      NewOuterConeAngle != OuterConeAngle)
   {
      OuterConeAngle = NewOuterConeAngle;
      MarkRenderStateDirty();
   }
}

That check for AreDynamicDataChangesAllowed() is what is causing the change not to take because the light isn’t set to be movable. So, to make it moveable, your code should read:

Light->SetMobility(EComponentMobility::Movable);
Light->SpotLightComponent->SetOuterConeAngle(5.0);

Then, if you want the light to be stationary again (or static), follow the above code with:

Light->SetMobility(EComponentMobility::Stationary); //or Static, accordingly

So yeah, that’s it. Once you’ve spawned your light, make it movable, make your changes to the light, and then make it stationary again. I hope this helps someone else who runs into this issue.