On click - check clicked actor and perform action

Hello everybody,

I’m trying to do the follow thing: When I click an actor, if it is an interactable actor → move to actor and interact with it when in range or if it is an enemy, move to it and attack. How would I set this up so it makes sense?

What I’m doing right now is : I move to click location, save the clicked actor → check with a branch if the actor is interactable ( implements interact interface) → if true, interact when in range. If not true, check with a branch if actor is enemy ( has tag Enemy) → if true, attack when in range ( perform an animation). It this way ok? It works so I guess it isn’t that bad …

My question is : is there a better way to set this up? For instance, somehow to check what the Hit Actor is an depending on the result do something.

I’m trying to replicate a system similar to Diablo where if I clicked an item , player moves to it and picks it up. If I click an enemy, player moves there and attacks. I tried using the interact interface for both actions but it didn’t seem to fit, I want the PlayerCharacter to do something if HitActor is Enemy, not the Enemy to do something.

Hope this is clear …

For instance, somehow to check what
the Hit Actor is an depending on the
result do something.

Have the interface function return data about the target. And you do not even need to check for interface implementation, the function will return defaults if there’s no implementation. As in:

First of all, thanks for the reply ! I am noob in UE4 so let me say what I understood:

1.Create enum EInteractionType (2 values right now since I only have weapons and enemies) : Weapon,Enemy

2.In my blueprint interface have a function called CheckInteractionType which returns what the interactable actor is

3.In my BP_Weapon I set the enum to Weapon, in my BP_Enemy I set the enum to Enemy

This is my setup - I have my input action Move in player controller similar to TopDownTemplate and after moving I save my HitActor , then , in my PlayerCharacter on EventTick I check if the HitActor which I’m getting from PlayerController is in range, then, I’m checking the interaction type like you see in the screenshot. Is this ok?

Also I attached my InteractEvent and AttackEvent, both set up on my Player Character. Sorry if this is a facepalmer, like I said I’m a noob in UE4 :slight_smile: Thanks for the help so far!