Best way to interact with objects in world?

Hey guys,

I’m relatively new to to Unreal, but I love it so far! I have a question about the best way to interact with objects in the world (collectible, doors, etc). I tried to search for an answer, but found a lot of conflicting advice.

So I want my interact key (E) to do several things:

  1. Collect collectable objects in the world.
  2. Consume consumable directly in world
  3. Interact with environment (open doors/etc)
  4. maybe more?

For example, I have a “battery” that you can pick up and store. I tried to place an InputAction In the “Battery” blueprint itself, but the keystroke wouldn’t fire. To solve this, I put this in my character:

72944-interact1.png

Then I have an EventTick listen for when the “InteractTrue” variable is true. Then I gate that including the batteries collision geometry.

This works well for the batteries (since the instance is destroyed on pickup), but when I tried to use the same setup for something toggle-able (like a door), The door opens and closes randomly. I figured out it’s because when I press the E button, It fires multiple times. If it fires an even number of times, the door does nothing. If it fires an odd number of times, the door opens/closes.

In this example the door itself has it’s toggle switch stored in the EventGraph of the map, and when I use “InputAction Interact” there, it works just fine.

Is the EventTick the problem? Is there something else better to use to have my Interact key work more globally? Which part of the Interaction should you store in the character, and which in the object he’s interacting with? Any advice that would point me to the accurate way to do this would be extremely awesome.

Thank you guys so much!

Hi man ,

this is a hard question , the best way is Always be simple, clear , and write the right amount of blueprint.
From my persepective i prefer that the object, the doors , and the consumable world have all just some variables, and if really needed like the door , some function to open and close.

I really prefere do all the work by my char.
A solution is often used is the Raycast . Because a lot of people want to point to the object they want to use.
In this case you can just cast the ray from the camera and check something like a variable to know if the object is a door or a consumable or anything else, and switching what they are you can cast them some events and stuff.

Otherwise you can check for all the Actors by class, or by tag … or build up a volume and then get the overlapping Actors from him and check just them… but if you dont have any particular situation you should use the raycast method.
Pretty sure that there are Always more ways to do things , end one methond fitt Always best.