How to get a click on character you want to heal effect going?

Hi there, I have an inventory and item system and I’d like to create a med kit item that can be used on the player who has it, or on another player nearby.

The way my system when the item is right clicked on and the “Use button” widget is clicked on it calls the Item Effect blueprint which is an actor class linked to the Item in the Item Data table.

However, I’m not sure how to get this to execute another click event as I’m new. My game is a third person shooter so I know I’d have to create a function that sees if any actors are around my player. But I’m not sure how to show my characters mouse button and then wait for an input click on actor event.

I’d like the player to be able to click on any pawn in a sphere around itself including itself and apply the heal.

Could anyone help with this?

Watch tut about blueprint communication.

Something like this:

Then use line trace to pick (select) actor to interact with. And do as above tut says but with results from line trace. You can also turn on drawing of line trace to see where you are aiming it.

Then get some tut about preprocesses or new outline material effect like this one:

Thanks I will begin coding this now. However, I have one more question.

I can see how I would use an item effect to spawn a line trace and perform an interact on a character. However how do I get the functionality above, where I click on the item to perform a line trace and then click on the actor to heal?

I can call an item effect to do something like a line trace, but I can’t seem to bind events to key presses within that item effect actor? Unless I’m missing something.

Actually I might know this - would the item effect perform the line trace and interact with anything the cursor touches, and then the interact would be an on hover highlight effect, and an on click heal event? Maybe I’m getting ahead of myself. I’ll see what I can code up.

When problem is too complicated split it into smaller ones, and repeat splitting until you get problems that you know how to code.

Start with simple blueprint communication:

  • make blueprint actor that finds player controller, and triggers event in player controller (use print node to see if that happened)
  • add dispatcher in player controller, make that actor hook to dispatcher, and only then fire event in player controller
  • add line trace in player controller, when one of actors is hit by such line trace, tell it to fire event (instead of firing with dispatcher)

Thanks I have no problem with any of that, very straight forward. I can begin to fire off line traces and generate collision with the target I want to heal. The problem is I can’t create an event that works off of a left mouse click. See image below, all I can do is do something every time the left mouse button is click.

I want a one-off event that fires when my mouse button is clicked. Let me try to explain again. When I use my item, the event is fired. I want the event to be fired after I use my item AND click the mouse button. I’ve tried the methods you suggested and have run into dead ends.

I’ve spent all day looking and I can’t find an easy way to wait for a click event, and then fire a function so please enlighten me if you know of one. All of the on click events I can find fire every time a click happens, not one time.

image

Edit: tried get key, didn’t work either.

You can get player controller and call “set show mouse cursor” to show the mouse.and fire a line trace to hit any pawn.but in my opinion it sounds weird using cursor to select in a third person shooter game.because it’s not convenient to look around when the cursor showed.I prefer to shoot a heal bullet from the gun or something

My game is kind of like PUBG where you have an inventory as well so sometimes an item can be used on another player. I can shoot a sphere overlap out but I’d prefer a quick cursor event.

I still don’t understand how you get the click to fire the event after the line trace, I can’t find any functionality to do that. A good example would be in WoW where you click a healing spell, and then click a character. Is there really no way to do that simply?

Not sure.but I think line trace is easy enough…you master it only with several time practicing.

Now where do you get stuck.can’t fire a line trace?

Okay I see it.let’s get it straight.
the system should be like: first left or right click the item in the backpack to use it.and then move mouse to click on one of the character to fire a line trace(left mouse button to fire) . when the line hit any character,we can get that character’s information ,so that we can call functions IN that character.
The whole point is not triggering event with any button.but with the line trace to communicate with other to tell it to do the event.(the heal self event I guess)

You could have a look at how the line trace simply set up.but I’m not gonna do the inventory part :joy:



have leftmousebutton call an event dispatcher.

one you use the item bind to the event, fire heal, unbind event

Thanks I get those parts, yes calling a linetrace and casting to the character it hits is simple. However look at your left mouse button event. It is called every time you click left mouse button.

I can’t put a left mouse button event in my item effect actor because it’s not a player controller, it has no LMB input. And the only LMB event I can put in my player controller is that one that fires when pressed.

I can’t specifically call an event in my playercontroller with a left mouse button clicked. Either the event in my playercontroller is called by the item effect, instantly or I bind an event to left mouse button click in my player controller, which gets called every time I click and not when I use the item. Neither of these work.

Do I need to override the LMB input for this one function in player controller? I’ve looking in my override functions for my player controller and there is no override KeyDown or Override LMB event. I’m not sure if that’s because I have my input actions and events coded in C++ though.

I’ve tried that but I don’t know how to call for the left mouse button press. My left button is bound to firing my weapon in my playercontroller.

‘Get Key’ seems to need an override key down event as input, which doesn’t exist in my playercontroller. Left Mouse Button event in playercontroller is an event that fires every time a mouse button is pressed. So neither of these work.

Do I add an event dispatcher to my FireWeapon event that normally happens on a left mouse button click? And then only bind the event when the item is used? Wouldn’t I still fire my weapon in the direction I am looking then or not?

well there are lots of ways to do this but for a simple way do this,

When you select an item to use, get the playercontroller and set ItemRef

OnLeftMouseButton pressed add a branch. Condition IsItemRef Valid on false FireWeapon. on true 'GetItem’Ref and call an interface event ‘UseItem’

Do your logic in the item so its modular, then set ItemRef to null on controller and firing will work again.

Now this works for all items, so say you want to target a grenade or use a speed boost. all works

Isn’t the item an UI element in the inventory slot? and if you don’t want the line trace to fire every time.you could add a condition check to it.when the item is used. set a Boolean to true. and LMB in controller check the Boolean.

1 Like

Thanks.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.