BP_LightManager - Need feedback on where can I improve!

Hi!

I’ve created this BP_LightManager which handles turning lights on one by one based on player distance.

I’m quite proud of how it turned out, since I’m somewhat a beginner in Blueprint scripting, however I’m wondering if there’s a better way of doing it, and if someone who’s better at BP could tell me where I could improve code?

Struct to control each light as I please

Begin overlap

Check nearby lights code


Variables

Check If finished Function

Full view

I’m also attaching Blueprint Link if it’s hard to see or understand

**BP VIsual representation Link : **

BP visual representation

So… scrap it and re implement it with the following ideas behind it - which may evolve over time or with more ideas.

  1. all lights are contained in some other BP.
  2. the manager keeps track of all lights with get all actors of class.
  3. gameplay tags exist. Could be used to flag on/off state.
  4. each light implements an interface.
  5. the manager makes interface calls to turn stuff on/off alacarte.

Additional ideas:
Direct line of sight option - turn a light off or on based on linetrace between player camera forward vector and position of the light (with proper math to determine it being within the FOV.

Illumination calculation - the manager has a built in function that determines how many lights are visible from a specific point (same line trace as before just used differently).

Btw, generally speaking loops are frowned upon. So even with get all actors of class i wouldnt go looping all the lights to do things with - thats where your overlap should come in.

Have a child BP that you can add to any actor which controls the overlap and detection - for that, you can indeed use loop so long as you do it peopelry and check numbers before the loop starts (avoid loops over 100). Should also use an interface because the manager gets to call on it.

Some other random thing:
Variable naming - go with something like I_counter for Integer, f_counter for float, s_counter for string etc.
Look up common ways to do it right and start using that proper naming so you have easier time later on when you move to code.

Another worthy point.
Add an actor variable - leave it empty. Check if empty. If empty and an overlap had occurred, set the var to the overlapped actor. Easy peasy. You dealt with the overlap and have the actor flagged to do whatever else sans needing to loop. (Does implement interface? Yes? Call “light up”) for instance…

1 Like

Don’t use any of the Get player XXXX (Index) nodes.


Incorporate BP Interfaces

Incorporate Many-to-One Event dispatchers (lights bind to Manager event)

Lights should be BP Actors vs simple point lights dragged into the level. As an actors you can add a sphere collision component of whatever size to auto detect the player (scale to light radius). This can be used for automation or 2 way communication with the Light Manager.

1 Like