Interaction with object by pressing E button using ue4 blueprints

I am a begginer in ue4 blueprints system. I've wanted to create simple code: player enter the trigger box, and press E, after that text should appear on the screen. What I did wrong in my code?

enter image description here enter image description here

Upvotes: 1

Views: 5130

Answers (2)

chhopsky
chhopsky

Reputation: 11

On Component Begin Overlap (Box) fires on the frame you begin overlapping. Unless you pressed E on the same frame you begin overlapping, this will not work.

For this to work, you would have had to be checking if it was overlapping and for the key press on every tick. Don't do that, it's a waste of time.

What you could do instead is On Component Begin Overlap, set a variable to record that you're ready to interact, and then check for that variable when you press E.

This is something I did recently using the Top Down template that demonstrates 'move within distance of object, press button, thing happen'

Adding an object to a 'ready to interact' array on overlap in Player Character.

Detecting a mouse click, checking if it was in the array, doing stuff in Player Controller.

It sounds like you're building an interaction system though, so if you want this to be as re-usable as possible you should probably have this code on your Player Character / Player Controller, and not in the object you're interacting with.

Upvotes: 1

Ben
Ben

Reputation: 89

I'm no expert, but I think you should use a branch node to check if the key is pressed. No harm in also changing your other character to a getplacyercharater.

Best of luck :)

Upvotes: 1

Related Questions