Disable attack

Hello, I would like to disable my Left Click attack then I press G (this also enable and disable my mouse cursor), so I can manage my inventory and drag items.
Every time I move something or select and Item, my character attacks and It is very annoying.

Anyone know any good trick or blueprint script?

Thanks .
:slight_smile:

Are you bringing up a widget when you press G? Because there is a blueprint node called “Set Input Mode” that disables or enables processing player input depending on what you want them to be able to do. It has 3 settings, Game and UI, UI only, Game only. So if when you open up your inventory widget (assuming this is the case), just add a “Set Input Mode UI” then before you close your inventory be sure to call the node to “Set Input Game+UI” or “Game Only” depending on your set up. Let me know if this helps.

Hello, have no widget when I press G, I just want to cancel the attack on the Left Click when G is pressed. but I will check your suggestion. Thanks, Nebula!

In that case a simple boolean to tell whether or not “G” was pressed prior to your “attack” script should do the trick. You would simple set the condition when G is pressed the first time and then again using something like NFlip-Flop. So first time pressed “Set Attack Mode Disabled” to true so additional clicks will not cause an attack, then when you press “G” again, set the boolean back, so “Set Attack Mode Disabled” to false, this way only when attack mode disabled is “false” will you be able to execute your attack.

Thanks again for the replay, sorry if I did something wrong, I just get “Can attack” on the print String. See my tree below!. I’m new at this so thanks for your patience.
![alt text][1]

So the “print strings” aren’t supposed to be there, I just used them as examples. You need to attach your actual scripting logic that you want to run after the branch. So the script would look like this

Also, hooking up both the “Flip-Flop” node output pins to the same thing defeats the purpose. You don’t want it connected to the show mouse cursor, you would always want the mouse to be displayed from what I can tell. What you want is to use that to disable the “attack” script you have and then enable it when not using your inventory items.

You just added the branch to the wrong thing. Should work with this set-up

Actually now that I see this code again, I am not sure where your “attack” is…where is the blueprint for what your character does when you click the left mouse button? You said your character keeps “attacking”…I don’t see any script for an “attack”. Wherever that stuff is, you need the “attack mode” branch before that.

Ok, Thanks for all the explanation, It is just great! It works but I can’t turn off/on the mouse visibility on the PlayerController as it breaks the G on PlayerCharacter. One G cancels the other one. !
The way it works so far is for me to turn off the G on PlayerController as you see on the image bellow.
[alt text][1]

Why would you want to hide your mouse cursor? Don’t you need it to see where you are clicking in the inventory? And also where you are clicking in the world to attack? I don’t exactly understand why it should ever be hidden? I would just delete the script in the player controller.

I hide the mouse cursor because I enter in Combat/action mode, to do combos and skills. When I’m not in combat I turn on the mouse to manage inventory and pic items. the issue is when I move an item my attack trigger and that is what we were trying to fix. :slight_smile:

So i think i may have the solution. Cast to your player controller, and get a reference to it in the character BP. Then hook up the switching on and off of the cursor visibility to the same Flip-Flop node as the disable and enable attack mode. I got this to work on my end with this set up so every time you hit G the cursor shows up and you are unable to attack. Hit G a second time cursor goes away and attack is enabled. (Also, I did not notice the way you did the Flip-Flop originally with the boolean output, it does make sense to have both hooked up as you see I have done it now. My bad haha, you had that correct! Both ways work but your’s saves an extra node. Anyway, try this out and let me know how it goes!

Also, in player controller uncheck “show mouse cursor”. This way you start off in attack mode, no cursor, then you hit G, cursor show up and disables attack mode, allows you to move inventory items, then hit G again, cursor goes away and you can attack again. I got it working perfectly on my end, hopefully you can too.

It worked like a charm, I did some research about casting and I was able to do it, just like you said. Casting is great! You just help me to Level Up Nebula, I know a bit more about Blueprints now.
Thank you so much, You are awesome! :slight_smile:

Awesome! Glad I could help. Can you mark this answer accepted, thanks! And good luck with your game

Cool and Done! Good lock on your projects as well! :slight_smile: