How do I check if player is in darkness?

So I’m making a stealth game and I want to check if the player is hidden in shadow. Epic’s James Golding suggested that I do a line trace against light sources, which works but I also want to check if the player is still in darkness, even when nothing is between them and the light source, but I’m not sure how to go about this.

Well, it seems like the solution to this issue is going to be light source type dependent and I will assume this is why you are asking… because you are using point lights or spot lights, not just a directional light.

For a Directional Light, this method of line tracing is ideal. You will always be in the light if you can trace to it.

For other types (point light, spot light), you will have to do something else.

Spot Light/Point Light

One option is to create a class that extends Light class and create a sphere componenet that allows the player to overlap collide with it. Then you would check for EnterOverlap events, make sure the overlapping actor is the player, then tell the player that he is in the light (however you want do that, make a function in the player class or something of the like). Then on the ExitOverlap event, tell the player he is no longer in the light.

So you can extend the Light class that you want to add a sphere component to it and then add the overlap event handling functions in there. Or, you can do this very simply in Blueprint alone. Seeing as this is a trivial task, the Blueprint overhead would be negligible. Also, you can make one blueprint and just plop a bunch of lights wherever you want and tweak little settings as you see fit.

Hopefully that helps a bit.