I’m trying to create an automated door script by figuring out if a player is looking at a door, and then playing the associated Level Sequence.
The door detection works perfectly, getting the actual level sequence works perfectly, however playing the level sequence does not. I walk up to the door and hit E, and nothing happens. I hit E again, and the door begins working perfectly. It toggles its ‘opened’ and ‘closed’ states and works fine.
I am not using booleans because that would mean having to set up a boolean for every door on the map (at least to my knowledge it would) to check if opened or closed. Instead, I use GetPlayRate and if it’s set to -1, then that means it is pending close - it plays at a rate of -1 to close, then I set it to 1 to say it’s pending open, and then when played it sets back to -1, and yadda yadda yadda.
That works perfectly, but I have to double tap E to get it to work the first time, and then it works flawless every time I press E after that.
As seen above, I check if the play rate is above 0 (I have tried with “== 1”) and if so, it plays it (so it opens the door) and then says ‘SETTING TO -1’ and sets to -1. However, what actually happens is, it sees that it is greater than 0, but it doesn’t play the animation, and it sets the play rate to -1. When I press E again, it opens the door and then says ‘setting play rate to 1’. Opening my door is when the play rate is at 1, which means the play rate is set before it plays, yet I have set it up in such a way that this shouldn’t be happening:
When I now press E, it prints ‘setting to 1’ and then opens the door. It prints ‘setting to -1’ and closes the door, the opposite of what I intended. It’s as if the play rate is being set before it’s playing, which would explain why the door ‘closes’ when it’s set to -1 (in reality it doesn’t even play the closing animation), and then opens at 1 again.
I tried playing it twice in succession but this did not help. I have tried swapping it around so that it works the way the ‘bug’ works, but if I do it this way, the door gets stuck open and doesn’t close, even though the play rate is being set to 1 and -1 respectively. The sequence itself is just a door rotating through 90 degrees.
Is there anything wrong with my blueprint setup? I for the life of me cannot figure it out and I’m pulling my hair out. I don’t want to use trigger boxes because I need to be able to detect when someone is looking at a door, or even a part of a door (like a lock), not just in a trigger box.
Level blueprint:
The door animation is attached to the door and then I use GetAttachedActors to find the animation of the door that is currently being looked at. I find that door by using a LineTrace, and then doing a for loop to check if any of the attached actors are of the class ‘Level Sequence Actor’. That part works flawlessly though.
EDIT: I also sometimes have to really spam the E button to get it to work. Like, I have to hit it in rapid succession about 8 times before it opens, and again, it opens the ‘wrong way’ (open then set to 1, close then set to -1)