x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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

Product Version: Not Selected
Tags:
more ▼

asked Apr 08 '14 at 11:36 AM in C++ Programming

avatar image

Solicio
200 54 53 64

avatar image JCipriani Feb 12 '17 at 08:54 PM

Did you ever find a solution to this?

avatar image JCipriani Feb 12 '17 at 09:04 PM

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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.

more ▼

answered Aug 30 '18 at 10:33 PM

avatar image

Ed.Kaminski
6 1 1

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question