Download

Getting an instance of a BP for object interaction

Hi Guys

I’m currently trying to find a decent way to get a generic ‘interaction’ system in place. The idea is to press the ‘F’ key and depending on the object (BP) the player is close to (i.e. within the bounds of a collision volume in the BP) I would like to get a reference to the instance of the BP and do stuff with it.

I’m now a bit puzzled on how to approach this in the ‘right’ way, and which funcionality should go where (object BP, character BP, level BP, game state)?

Can anyone nudge me in the right direction here?

Cheers,
michael

I don’t mean to be rude but, this is all covered in the youtube series on blueprints.

I think it’s video number 8 that you need. Unless you are talking about something different entirely?

One way would be to call a Sphere Overlap originating on the player that would give you a hit result of the object you are trying to interact with. The sphere could extend 1 meter from the player or a hundred. If you had multiple items in the sphere you could distance check them, or check if the player is facing one of them, etc.

Alternatively, if you want to get a hit under your mouse cursor a line trace might be more appropriate.

You could also Get All Actors of class, but I generally only use this if I know there is only one such blueprint in existence.

I would put the sphere overlap and the Input(F Key) in the character bp. Put whatever function is being called on the object in the object bp.

I’m well aware of that and it is not what I was asking - perhaps I wasnt clear enough.

Anyway, I solved it in the mean time - I’ve got it working with a game state bp.

Out of curiosity, what was it that you were looking for, and how was it solved?

I wanted to implement generic interaction behaviour. So if the player stands close to an interactable object, he can press ‘F’ to interact with it. Now, depending on what kind of object he stands at, ‘F’ does something different.

Here’s an example:

  1. Player stands at an equipment crate: ‘F’ opens it and puts the contents in the players’ inventory
  2. Player stands at a phone booth: ‘F’ lets the pawn pick up the phone and do a call

My current solution is to track a game state variable ‘curentInteractibleObject’ which I’m populating whenever the pawn enters an interaction trigger volume. Then I do a custom event in the GameState which is triggered when the player presses ‘F’ (which is handled in the char bp). The logic in the game state now takes the object (which is now stored in the mentioned variable) and branches to specific functions based on the class type of the object.

I use a tag and compare if have tag “pickable” the pick if have “door” tag open/close… not good?