Opening Blueprint Doors with Cast

I have a Door in a Blueprint that is duplicated about a dozen times throughout my scene. I am using a cast on my pawn so when the door is clicked, it opens the door by triggering a “Play Animation” that opens the door. Then closes the door when clicked again using a “FlipFlop”. My problem is that if I click on one door and it opens, then click on another door, the flipflop fails because the first door was already opened. What is the best solution to create doors to open and close that are part of the same blueprints without the state of the other doors effecting each other?

Each placed blueprint actor should be unique for how it functions. Can you provide some screens of how youve set it up?

I just programmed a whole bunch of doors! The best way is to get rid of that flip/flop in your player blueprint. Instead, create a Boolean variable in the door blueprint for whether the door is open or not. When you click the door, call a function in the door blueprint that checks the variable and then acts accordingly.

Nersbeware,

That sounds like the right approach! I will give this a try, thanks!

Nerdsbeware,

I tired this approach but I actually made it worse. All doors open when clicked and the close animation is ignored. Below is a screenshot of my Door Swing Function. This function is on my Door Blueprint and only fires when the doors are clicked. This works well, but all the doors open as described. How can I get each door to open individually and closed after its been opened?

Teriander,

Looks like the close animation is being ignored because your branch is hooked up backwards. The variable starts at true and is set to true, it’s not being changed.

It sounds like you are using one blueprint for all of the doors? You need to have just one door in the blueprint and place multiple copies of the blueprint around the level. When you click the door, you need to get a reference to the instance of the specific door blueprint you clicked and then call the function on that instance.

In my game for example, when I press the use key I draw a trace to the middle of the screen (its first person) and use break hit result to get the reference to whatever was hit. If the actor I hit implements my custom interface for usable items, I call the function from the interface on that specific actor.

Now if you are doing just doors, you may not need the interface. Instead of that you can just check to see if the actor you clicked on was of the type of your door blueprint.

I’ll try to grab some screens of my setup for you when I get home this evening.

Nerdsbeware,

Thanks for the feedback. Your suggestion on the close door problem works. The doors now open when clicked, then closed when clicked again. Now my only problem is separating them so they all do not open and close. I do not have all the doors in a single blueprint. It was a single door blueprint with a single door mesh inside of it, then I copied this door blueprint about 6 times. The sounds like its exactly the way you have instructed, but all the doors still open every time a single door is clicked. I guess I need to figure out how to “get a reference to the instance of the specific door blueprint”. This is probably where I’m stuck.

Also, forgot to mention that my Event comes from “MotionContoller(R) Trigger”. This is for the Vive controller. So I have the line trace on my Pawn, an Event Dispatcher that is called at the end of my line trace. Then my Door Blueprint has a bind to a “DoorSwing” event. This DoorSwing event called the function in the screenshot above. Here is a screenshot of the Door Blueprint:

952087926fad4fa15189bb53743039bc0b5a4172.jpeg

Ah, ok. I haven’t used bind to event before, but I would suspect it has to do with that. Perhaps the event is being called universally, i.e. every where that event exists it is being called? I’m not sure.

Instead of that, try using breakhitresult after your line trace, draw a pin off of hit actor, cast to bp_door, drag the execution path from that and select your door swing function. That should all be in your pawn bp. That should do it :slight_smile:

Break Hit Result is what I have been using. If any of the doors are clicked, they all execute the DoorSwing function on my door. Could it be because I am calling from a “Event BeginPlay”? Question, is it possible to set a “OnClicked” event on my Door BP that executes when my Controller is pointing at the door and clicked? Here is a screenshot of my Pawn with the Line trace and Event Dispatcher:

So I did some research. And the answer is yes that’s part of it.

So an event dispatcher basically tells the ENTIRE game that an event took place. Now every actor, in this case every door, that has an event bound to the dispatcher will execute that event. Since every door is registered at the start of the game, every door will fire.

What you need to call is a function, not a dispatcher. Which you already have, I believe you named it door swing. So in the last screen you posted, delete the event dispatcher node. On the cast node before it, drag off the As Door_BP pin and type door swing in the context menu. This allows you to call the function in the specific door you hit with the trace.

Nerdsbeware,

That sounds like a solution. I will give this a try this weekend, could be Monday. I’ll let you know how it goes. Thanks for the idea!!

Nerdsbeware,

I confirmed this works! Good to know the dispatcher will have a global effect. FYI, my final results required NO CODE on the door itself. Everything was entirely driven by my Pawn and each door opens and closes individually. Thanks again for your suggestion!

Awesome!! Glad it’s working!