How to enable and input when looking at a blueprint actor

hi everyone, I’m new to UE4, and I need some help. I made a blueprint for a door and i would like to only allow it to be opened while I’m looking at it and inside of a box, but i also want it to be opened while inside of a second, smaller box, without looking at it. im not sure how to enable the input base on if the player is looking at the door.

any help is apreciated, and if you do help thankyou so much.

i was able to solve my problem, the answer from herb64 was a lot of help, but i also privided more details on how i solved this problem in my own answer. since herb64 was the one who pointed me in the right direction, he gets the credit and the correct answer mark. thankyou so much btw, you really helped.

Can you draw this? It sounds like it might be a bit confusing to the player…

You will need to do a LineTrace from the player to the door to when the player is inside the first box to check, if the player is looking at it. As to the overlap with the boxes, it looks like you already solved this by using the Begin/End overlap events. Search the docs for LineTraceByChannel

yeah, i already figured out how to anable/disable based on which box(s) the player is in, but im still having trouble telling if im looking at the door or the wall, or nothing. i only want the player to be able to open the door if they’re close enough, or if theyre looking at it. i got the distance to the door part, but ive been trying for about 3 hours and cant figure out how to get the looking at the door ppart right.

UPDATE: i got it working to the point where the door opens if im looking at something, but im stuck on how to tell what im looking at. i have two doors close together, and the collision boxes for the two overlap, so one will always open and one never opens, no matter where im looking. i need help figuring out how to tell the engine which door i want opened based on which one im looking at.

ive attached two pictures of the blueprint, for referance.

Here’s an example for a linetrace. Test Camera is the player camera component. We get the position of the camera and add some direction vector in the forward direction of a given length (here 300) and put these into the line trace function.

The trace function returns, information on any objects hit by the line trace. If return value is true, something has been hit. The Hit Actor holds information about the object being hit. In my case, I just check, if this object implements a given blueprint interface, and if so, I set a variable keeping a reference to that actor and show some HUD information. But you also can do anything else with that Hit Actor, in your case, check if it is the door.

Now you have checked, if you are looking at the door, or some other object or even nothing (e.g. length of vector too short to hit anything).

I hope, this is helpful to you.

Edit: we did overlap in posting - in your code, you do not check the Hit result to get the actual information, which actor has actually been hit by the trace. So how could you know, which door was hit, or if it even was a door?

ok, so i got it working the way you sho, but now both doors open. im using the same blueprint for multiple doors, and the only way around it that i can find is just duplicate the blueprint and make each door have a different BPI, which seems in-efficient. is that the best way to do it, or am i missing something? also, your answer helped a hell of a lot, but im on the new side and still a little confused. thankyou, btw


so, i was finally able to solve my problem using the following blueprint below. just to simplify things for other newbies like me, i removed the smaller box that would trigger other events, and now the only thing here is for opening a door when you look at it and press E.

using line tracing, as herb64 suggested, i was able to get it working using a blueprint interface, and checking if said door implaments it. this was all herb64’s suggestion, so all credit goes to him.

i was a little confused at first, but i figured out i could make each door a new blueprint interface, and then only use each interface on one door, and that allows the blueprint to tell them apart, using the “does impliment interface” function. most confusion can be cleared up by searching on youtube and watching how they use these things.

some things like the open/close door animation and the does impliment interface require a more visual tutorial, so i recomend looking on youtube if you dont fully understand how they work.

i hope i was able to help anyone who’s having the same problem i did.