How to make to compare if players look at door?

I have door open BP scipting, via timeline node. and of course I use trigger box to detect when is player at door. When player come to door and press E - door open. Simply, like tutorials from you tube.

But I want that door will only open when:

1.) Player is on trigger box.

2.) When player look at door.

How to do that?

In player blueprint - I made simply line trace by chanell, to print on screen object name that I am looking. And this is working great. When I look at door - it print “” etc. When I look at landscape, it prints “LandscapeMain.1.xxxx”…

But how to tell to door - that every tick door must compare if player is looking at door? Is there some node that automaticaly check if player is looking at some object, or I must tu make fName varibale to save object name, and then check every single frame what is player looking?

Make a variable that stores the Hit Actor Reference of the Trace.

Then create a new event with your input Key (Lets say “E”)
So its
Event input “E” Pressed -> get Hit Actor Reference Variable -> is valid -> true -> cast to Interactable Object (or your Door Class) -> Cast success -> Call “Open / Close” Function / Event of the Door Actor given by the cast

If you you want add the trigger:

Go into the door blueprint, select the box collision of the trigger, create a new Event On Begin Overlap
Get the Actor of the begin overlap event, cast it to player, set a variable bool (lets say isPlayerInTrigger) to true.
Make a branch check for that variable in your Open / Close door function.

Thanks, but which variable to use, String or Name?

None of em.
If you click on change variable type, you can type in stuff in there.
You’ll type in the name of the door blueprint name, it should show up in the list.
If you move over the List entry of Door, you should get 3 types to chose.
You take the first, the blue one, named Reference.

That means, you can access this door actor from this variable (if its set. That’s why you should check for “is valid” on the “E” Key event) - ( it’s “pointing” to the door actor in your world while set)

Get Doorvariable -> Set visible
Get Doorvariable -> Destroy actor

The Trace Line will give you a “Hit Actor” (or Other Actor, something like that.) as a result. That’s a “pointer” (like above) to the object in your world.
You store that pointer in your variable which i was talking about, so you have access to the door actor through it.

I have one crazy idea how to do this.
Place box collision to camera, values like 1x1x100. Start at camera and finish on point where you are looking (this will be done when is that box attached to camera).
If you overlap area where you want to open doors, activate that camera box collision and check begin/end overlap… and based on overlaps, drive some func in tick (door rotation probably?)

You are better of just making a linetracebychannel and then if it hits the door open the door.


Yes, I made linetracebychannel, and it is activated when player steps into trigger box. And works fine, very simple.

But one problem - line trace shoot only one time when I step into trigger and then stop, why???
If i move out from trigger and step again, it again shoot only one trace line.

You can get what you want by sending the LineTrace within your ‘E’ input event.

Anyway, your solution isn’t very beautiful in my opinion. I wouldn’t place user input events in the door blueprint. Similar to what KrautPotato posted I suggest the following. I quickly created this by modifying blueprints of mine, so keep your LineTrace start and end, the logic behind your timeline, replace BP_PlayerCharacter by FirstPersonCharacter and BP_Door1 by MainDoorRight etc.

These nodes should be in your FirstPersonCharacter Blueprint:

These nodes should be in your MainDoorRight Blueprint:

Btw are you sure you need the CollisionBox around the door to check if the player overlaps? In most cases you’re fine if you choose the float you’re multiplying your ActorForwardVector with wisely.

Pepeeee - thank you very much, this is much better than my script. But I have only one problem - how do you connect “Cast To BP_Door1” target with “Open” function target??

I cant connect that target, after “Cast to…” variable, I call new event and call that “Open” or similar, but I cant connect target from that event and Cast To variable…

At first make sure you created the custom event “Open” in your FirstPersonCharacter Blueprint and you compiled that Blueprint.

Afterwards in your FirstPersonCharacter Blueprint, the cast in your example should be a “Cast To MainDoorRight”. To find the “Open” event, you need to click and drag the “As MainDoorRight” output pin anywhere in your EventGraph and search in the resulting context menu for the “Open” event. Alternatively you can just rightclick the EventGraph, uncheck context sensitive and search for the “Open” event here. Make sure you use the one of your MainDoorRight, there are multiple ones here.


Yes, I made OPEN event, and look at picture - this is problem, I cant conect CastTo to OPEN event target.

The OpenDoor event has to be inside of your MainDoorRight Blueprint, not inside your FirstPersonCharacter.

Oh yes, now it works very fine, and I delete box collision, it is now necesery.

Thank you very much!

Still have some “bug”, I mean, first time when I start game, I need to press “E” twice time to open door. Then it works fine, I dont know why is that.

And another question, I dont want to start new topic.
When I pick up some object via psychic handle, and when I look to landscape with object - it launch me in air like rocket :smiley:


Guys, what to do if I will have a etc 50 various doors in my level - I need for every single door to make CallTo function in PlayerBP? That will be very much CallTo functions :slight_smile:

Generally the easiest way would be to let all doors inherit from one Master door class. In this class you implement your Open function. As long as all of your doors open by rotating one mesh this will be fine. The mesh that is rotated obviously needs to exist in the Master door class. You can change it then in each of its child classes. Now you only need to cast the HitActor in your FirstPersonCharacter to this Master door class and call Open on it. This should work for all of your doors. If you have doors that open differently (e.g. sliding doors) you have to override the event Open in those classes.

Thank you again, I got it!!

Please, look this:

I have light object which is converted do BP, with point light.

And here I have custom Event “TurnLightOnSwitch” connected to point light at my light object.

So, I want when my light switch is hit - to turn on/off that point light.

In my FirstPlayerCharBP I made another line trace to detect switch when E is pressed.

When switch is pressed by E - switch have some animation to looks real + at the end I want that switch send that “TurnLightOnSwitch” information to Point lightXXX on my lamp.

I connect CastTo my lamp, and at the end I need to connect target - but target is my point light on lamp.

But I dont know what to connect to target, which is inherited from basic mesh.

I mean - if point light is separeted from lamp, this can be done in same way like door.

But what when I have inherited object attached do basic object in BP?

So a nice way to do this is to create a variable of type HandLamp01_Blueprint Reference in your switch1 Blueprint. Make this variable Editable. Now you can plug this variable directly in the TurnLightonSwitch node at the end of your SwitchPress node.
In your level editor now click on one instance of your switch1. Because your newly created variable is editable you should now see this variable in the details panel. Set this variable to the instance of your HandLamp01_Blueprint you want to switch on with this exact switch1 you have currently selected. Your switch should now turn on the correct light you want it to. Of course you need to do this for each of your switch1 instance you have in your level.

Generally I guess you will have more than only one lamp Blueprint. Therefore I would suggest you to make the same I told you about the doors. Create a Master Lamp Blueprint each of your lamp inherits from, implement the TurnLightOnSwitch function here and make the lamp reference in your switch1 Blueprint be of the type of your Master lamp Blueprint. Now you should be able to turn each lamp on with this switch1.

O yeaaa, it works!

I tried your way, and it dont works. But then I convert that variable to array, and it works now. So after SetRelativeRotation, I called a ForEachLoop node, connect that node to TurnLighonSwitch, and variable to array and array element (that I saw on you tube).

And after that, I just picked in details on my switch - which lamp I want.

And just need to replace position of event TurnLight, before Timeline, because I have light show :smiley:

But now is little stupid that all light is instanced of MasterBPLight, and all lights automatic is ON when I start game.
Now I must create another MasterBPLight which will be OFF when I start game.