How to Detect if a player is in the shadow?

Especially a movable light source which cast shadow of a building or something on the ground runtime. How can i know if the player is in the shadow? Is there a any solution?

You could try doing line traces in the direction the light is pointed.

there is a BP function called something along the lines of “random vector in cone” that you can use for spot lights.

I do a similar thing for a basic AI I have been working on.
It does N traces in a cone pointed towards the player to determine visibility.


Thank for you reply, actually I’ve think of similar way by set up a ray from the player. The direction of the ray is just opposite of the directioal light (if point light, the dir is player to point light). if the ray hit a building object, it means player is within the shadow of this building.

I’ve already triey to enlight another way by access the material of player. Technically the mat of it’s render part. Because if the rendering object is within the range of shadow of a object, the object will also cast shadow on player’s render part. So if I can manage to access it’s mat and access it’s shading data(it’s pixel data), maybe I can finish this function by this way…, but still I’m not very fimiliar with Unreal Engine 4’s shading part, how to modify HLSL etc. (I think i can do this way in Unity3d)

Accessing the GBuffer for the lighting info would be best, But I don’t know of any one who has done that.
It may require devling into the source to see how everything is setup.

I am also interested in a good performant way to do this.

I was wondering if using an Environment Query, using a “hidden from light” filter setup would work (especially for a torch.)

I am a noob, so I wouldn’t know how to go about actually setting this up. Just a thought though. :slight_smile:eqs