I know this is not the perfect solution, but you could you this one:
Make a Timer for 100ms or similar. Then do a Single Trace Line and check, if the HitObject is your object. If it is, turn the light on, if not,turn it off
If you can’t really imagine what I mean, I could do a sample BP
Here’s an example of a setup you could use inside of a place-able Actor Blueprint that has a Point Light as a component:
Basically, every tick (frame) this blueprint does a line trace from your Player Character’s location to a location straight in front of it that is determined by the forward facing vector * the distance you want to trace out (this is where you could set a distance limit so it only activates the light if you are close to it). The trace is then checked to see if you hit the object that’s doing the tracing and, if so, turns on the light.
I just want to point out that in addition to Steve Allison’s solution. If you’re character is traversing the world space, the Player Direction and Distance is not enough to calculate the Line Trace. Make sure after the X node to add a Vector + Vector not that connects the X with the Player Location. This will allow you to trace even if the player is moved from their spot.
Okay so if you are using the First Person Blueprint Template:
I created a Simple BP with a Static Mesh of a Lamp & and a Pointlight. My Root element is a capsule component.
A Function with a Boolean Parameter inside the Lamp sets the visibility of the Pointlight to the value of the boolean
The rest of the VCode is inside the MyCharacter BP fired by the Event Tick
Create a new Actor* Variable in the MyCharater BP
you need to correct where the Crosshair is because its not completely renderd to the middle of the screen
as for Part 1 its a simple Line Trace but we need to make the trace come out of our “face” either we get strange results because the trace is not exacly where we are looking at.
We need to raise the Z value of our starting Vector to the Z value of our camera component wich is 64 by default.
Oh and if you want to lower or raise the range of the trace alter the * 1000 node
Part 2 checkts if our trace did hit something if not we check if our Last Lamp Actor var has a value if so we simply turn the light off (we may need to set the light actor to nothing after that… forgot to do that)
if we hit something we turn of the light of the last lamp we traced and afterwards we cast the actor we just hit to our Lamp Class and turn the light on if that was successfull
this should be everything you need to work with
(as you may have noticed english is not my native language… but i hope its still comprehensive
I’ve got it set up slightly differently. I never use a missed trace to change anything. There is an almost unnoticeable delay after looking away from the item, but I find it scales easier to multiple different items.
I have the trace from the first person camera [using location and loc + (x*forward vector) as start and end] send an event to the object through a blueprint interface, which then turns on a lamp with a do-once and then a retriggerable delay that is longer than the trace interval (.2 sec seems to still work, much shorter will cause it to flicker), to turn off the lamp when it no longer gets any additional traces telling it to be on. Once it’s turned off, I reset the do-once to turn it on for the next time it’s looked at. This way you can choose whether it turns off (almost) immediately or after a little while depending on the delay length. And it shouldn’t ever stay turned on because of weird trace hit results or fails not firing as intended.
This is the event on the item, after the line trace (per tick) from the player causes it to fire on that item.