Announcement

Collapse
No announcement yet.

Dynamically creating lights and Performance question.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Dynamically creating lights and Performance question.

    Hi, i'm currently working on a small game in which you will need to re-direct light until it hits a certain point in the level. You re-direct the light by using mirror that can be rotated around etc.
    i'm currently using line tracing to calculate the reflecting light, and these line traces are updated each tick to keep the lines up to date in case the player in some way moves anything that might affect the light in some way.

    Now i have a question regarding the lighting the reflecting light should give off, i'm thinking of having so when the light hits a reflecting surface and the line trace reflects in a certain direction to dynamically create a spot light at the hit location of the line trace and set the rotation of that light the the new reflected direction.
    But since i update the line traces each frame this sounds quite heavy on performance, so i'm wondering if there is any alternative ways for me to do this or will i have to create and delete lights each tick?

    #2
    I don't think traces will be heavy on performance in this case.
    You don't actually need to spawn/delete lights each tick, it's enough to spawn them once and then just update their transform according to new hit result.
    Alone: The Untold - a story driven horror game

    Comment


      #3
      Instead of spawning spotlights, try to move them and rotate it with surface normal. When the trace is invalid simply set the spotlight brightness to 0.
      Support my RTS Game (Agora) on Patreon!
      Unreal Nexus - Create Share and Experience!
      Unreal Engine 4 World-Wide User Map

      [PLUGIN] Aws Gamelift Client Plugin
      [TOOL] Create your own binary release of UE4 from GitHub source
      My UE4 Tutorials and Misc Tools

      Lead Programmer at YetiTech Studios
      Your Friendly Neighborhood
      Satheesh PV (a.k.a RyanJon2040) | Twitter, Instagram, Facebook, LinkedIn, YouTube, Google+

      Comment


        #4
        That could work, i'll have to give that a shot. Thanks!

        Comment


          #5
          I have a follow up question about the lights, i decided to try out having a max reflect number that limits how many times the line trace can reflect and then create that amount of lights.
          What i would like to know, how do you dynamically create light components? I tried the StaticConstructObject function but could not get it to work the way i wanted it to.

          Comment


            #6
            Code:
            GWorld->SpawnActor<ASpotLight>(ASpotLight::StaticClass(), Location, Rotation);
            Alone: The Untold - a story driven horror game

            Comment


              #7
              Originally posted by Solicio View Post
              how do you dynamically create light components? I tried the StaticConstructObject function but could not get it to work the way i wanted it to.
              What problems did you run into? Something like this should work (placed inside your Actor class):

              Code:
              USpotLightComponent* NewSpot = NewObject<USpotLightComponent>(this);
              NewSpot->RegisterComponent();
              NewObject is just a slightly more concise version of the ConstructObject syntax.
              Lead Programmer - UE4 Animation/Physics/Audio Team - Epic Games
              Twitter: @EpicJamesG

              Comment


                #8
                I managed to get creating the spotlights working the way i wanted it too although i'm running into some issues with setting the OuterConeAngle of the spotlight which you might be able to help me with.

                This is my current code for creating the light but if i add in the line that sets the OuterConeAngle i get errors. It works fine without it.

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

                ASpotLight* SpotLightTemp;
                SpotLightTemp = GWorld->SpawnActor<ASpotLight>(ASpotLight::StaticClass());
                SpotLightTemp->SetEnabled(true);
                SpotLightTemp->SetBrightness(Brightness);

                SpotLightTemp->SetOuterConeAngle(2.0f);

                SpotLightTemp->SetMobility(EComponentMobility::Movable);
                SpotLightTemp->AttachRootComponentToActor(this);
                SpotLightTemp->SetActorLocation(GetActorLocation());
                SpotLightTemp->SetActorRotation(GetActorRotation());
                SpotLights.Add(SpotLightTemp);
                }

                This is the error i'm getting.
                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\Documents\Unreal Projects\Temple\Intermediate\ProjectFiles\LightOrigin.cpp.obj
                Last edited by Solicio; 04-09-2014, 09:39 AM.

                Comment

                Working...
                X