Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How could I charge a weapon by holding down the fire button?

Hey guys I couldn't find a repeated or hold function from input and I tried to set up a timer to charge a weapon shot. Need help!

Product Version: Not Selected
more ▼

asked Mar 30 '14 at 04:53 AM in Blueprint Scripting

avatar image

1 3 4 4

avatar image [Epic] Gribbs ♦♦ STAFF May 30 '14 at 07:56 PM

Hi cloudnine1098,

We have not heard back from you in a few days, so we are marking this post as Resolved for tracking purposes. If you are still experiencing the issue you reported, please respond to this message with additional information and we will offer further assistance.

Thank you.

avatar image haruna Dec 18 '15 at 07:24 AM

If you're using a key and not the touch pad, you can use this Blueprint by Steve Allison.

alt text

More here! https://forums.unrealengine.com/showthread.php?476-Input-Held-Down

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

4 answers: sort voted first

Try this:

  • Wire your input's Pressed pin in to a While Loop

  • Create a New Bool variable, Call it what you'd like, it'll be used to determine whether or not the button was released, Have it set to False by default

  • Drag it to the blueprint, Click Set, and make sure the check mark is clicked in that Set node

  • Proceed to Wire up your logic for however you wish to handle what happens when the button is released

Next we'll focus on the Pressed logic

  • Grab the Release variable again and click get this time.

  • You'll need something to compare the Charge to the full value, So grab your Charge Variable (i assume you have one) and hit Get,

  • Drag the pin from the variable and type in Equal(float) or click on it once you see it on the list

  • Type in the Max Value of your charge on the second pin...

  • Now You have a choice: One way is faster, the other is more readable, i'll explain why

Option 1) - Grab the red pin from either the Release or the Charge Compare nodes and apply a NOT Boolean to either one of them - Connect those two to an AND Boolean and wire that to the pin

Option 2) - Instead of all that, you can instead optionally wire both of those up to an OR boolean then wire that to a NOT boolean

They should both function the same, Option 1 is a bit more verbose, Option 2 is slightly less stuff, uses an optimization trick i learned in a digital logic course,

Anyway, Wire the end result of whatever option you chose to the Condition pin of your WhileLoop Node. Wire Charging logic to the Loop Body Pin (Usually an addition and a delay would work good here) Also Add logic to the Completed pin,

Hope it helps!

more ▼

answered Mar 30 '14 at 05:49 AM

avatar image

58 2 5 10

avatar image cloudnine1098 Mar 31 '14 at 04:53 PM

Wow thanks for the help speewave! I'll try it out today!

avatar image speewave Mar 31 '14 at 11:11 PM

No Problem, Message back here if it was a bit unclear about anything, i can recreate it in a Blueprint and post the screenshot!

avatar image AUTOSOUL May 15 '14 at 03:48 AM

This is a while back but if you could post a screenshot that'd be really helpful!

avatar image speewave May 16 '14 at 04:39 AM

alt text

Hope it helps...

The functions shoot and charge are just blueprint functions and in my case are just place holders...

Let me know if you have any questions

capture.png (126.2 kB)
avatar image Dieselhead May 30 '14 at 08:30 PM

I don't have a lot of experience with the Blueprint system yet, but all my programmer instincts tell me this locks the blueprint or game in the same tick until the thing is charged?

avatar image AUTOSOUL Jul 13 '14 at 01:03 AM

Oh excellent thanks heaps, sorry for the delayed response.

avatar image AWYN Apr 27 '14 at 01:54 AM


I tried the WhileLoop method with a custom projectile for full automatic firing. Somehow the Play mode stopps immediately when I press the fire button!

I have a delay at the end with a Shot Finished bool - so it can't fire up quadrilions of projectiles at once. Right after the While Loop a Branch checks the Shot Finished bool. If it's True it sets the bool to False and then comes the projectile stuff... The delay works without the Hold bool before the While Loop but not with it.

Do you have any idea?

avatar image speewave May 16 '14 at 04:40 AM

Sorry i'm a bit late, i've been extremely swamped lately... Anyway, if you're still having troubles, send me a screenshot of your layout and i'll see what i can do

avatar image AnxGotta May 16 '14 at 12:49 PM

You do not want to increment the chargeValue in a while loop, that is very bad practice in this case. Do what iniside said below... use a boolean to manage the increment inside the Tick() function. This even gives you a DeltaTime value so you can use the passage of time to do the chargeValue.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The easiest way is to do it, is to do it in Tick(). Assuming you derived from AActor or implemented your own ticker, it is fairly easy to do.

You crate two Input options OnButtonPress() and OnButtonReleased().

You will also need some way to track "state" of weapon chargind, to check whether you are charging weapon or not. In header create variable:

 bool isWeaponCharging;

Now: OnButtonPress() { isWeaponCharging = true; }

You also need some helper variables: float currentChargeTime; float MaxChargeTime;

In your Tick:

Tick(float DeltaTime) { Super::Tick(DeltaTime)

     currentChargeTime += DeltaTime;
     if(currentChargeTime >= MaxChargeTime)
         currentChargeTime = 0;


that's it. you can make it more sophisticated by passing currentChargeTime to function that will charge weapon, and determine from that value,power of shot.

more ▼

answered May 16 '14 at 08:42 AM

avatar image

1.6k 105 97 185

avatar image speewave May 16 '14 at 05:58 PM

Good for C++ code, but this seems to be needing a blueprint implementation...

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

I tried Speewaves version but pie would quit on me when I let go of the mouse - similar to AWYN. I'd like to try Inisides verion but he lost me at "the easiest way to do it would be" Would someone be so kind and show what it looks like in BP? (BP now stands for Baby Pictures)

more ▼

answered Jun 07 '14 at 12:26 PM

avatar image

66 6 8 12

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Actually was doing something similar to this just today (auto repeating fire button) and found using a Gate is a really nice way of doing it


more ▼

answered Jun 13 '14 at 10:47 AM

avatar image

361 10 18 26

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question