x

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"

I need help with loops?

Im trying to make a health thing for an fps and im trying to make it say "if health is less than 1 wait 5 seconds then add .01 health every .1 seconds until health equals 1" but it keeps infinite looping this image is what i have so faralt text

Product Version: UE 4.22
Tags:
capture.png (86.3 kB)
more ▼

asked May 17 '19 at 01:43 PM in Blueprint Scripting

avatar image

rubiksmaster02
3 1 3

avatar image DonBusso May 17 '19 at 03:57 PM

Hey there, I think you're trying to over complicate it with loops. I have made a simple setup that should work for you. Made some comments above the notes, hopefully it will be of some use to you.

What happens here is when you press X you will wait 5 seconds then your health will start regenerating 1% every 0.2 seconds. Setting the bool in the first branch will prevent from health regen being run more then once at any time, you have to wait until you are fully regenerated, at which point the bool is set to false again. The rest is just a simple CustomEvent running over (looping) unless your health has fully regenerated.

alt text

How it looks in game (YouTube)

basicregensetup.png (420.3 kB)
avatar image rubiksmaster02 May 17 '19 at 07:20 PM

i dont want you to have to press anything i want it to auto regenerate, my end goal is "i want it to be if health drops below 100% wait 5 seconds and start healing 1% every .25 seconds, but if damage is taken while regenerating, stop and wait another 5 seconds to start regenerating... if health = 100% stop regenerating"

avatar image rubiksmaster02 May 17 '19 at 07:21 PM

what you put wont mix with my end goal.

avatar image DonBusso May 17 '19 at 08:28 PM

Sorry to hear you didn't find that useful. This was just an example, and if you would take another look at code and then read your comment you should know the answer. Instead of using X key as a trigger use Event Any Damage. As long as you are taking damage the counter will reset to 5 and once you stop receiving damage and counter will run down to 0 your health will start regenerating at 0.01/s until fully restored or if you take damage again.

I have just made this in blueprints.

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

2 answers: sort voted first

i dont want you to have to press anything i want it to auto regenerate, my end goal is "i want it to be if health drops below 100% wait 5 seconds and start healing 1% every .25 seconds, but if damage is taken while regenerating, stop and wait another 5 seconds to start regenerating... if health = 100% stop regenerating"

This has worked well for me in the past:

alt text

It waits for 3s to begin replenishing health and resets if more damage is dealt while regenerating or waiting to regenerate. You can adjust the percentage via the HealthRegen and Time interval is on the Set Timer node. The Retriggerable Delay controls regen cooldown.

capture.png (286.3 kB)
more ▼

answered May 17 '19 at 07:50 PM

avatar image

Everynone
14.8k 77 25 62

avatar image GarnerP57 May 17 '19 at 08:52 PM

I just realized I can remove the Blueprint grid in Editor Preferences -> Appearance. That's nice.

avatar image rubiksmaster02 May 17 '19 at 09:32 PM

what is "set"

avatar image Everynone May 17 '19 at 09:43 PM

what is "set"

Assigning value to a variable.

avatar image Everynone May 17 '19 at 09:44 PM

That's nice.

It made me obsess less about alignment ;p

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

This is how I would do it. Add Health

Event Graph

more ▼

answered May 17 '19 at 08:36 PM

avatar image

GarnerP57
816 3 4 8

avatar image rubiksmaster02 May 17 '19 at 09:20 PM

im new to blueprinting and this is confusing, how would i do this if i literally just made health as a variable

avatar image rubiksmaster02 May 17 '19 at 09:21 PM

like wth is event any damage

avatar image GarnerP57 May 17 '19 at 09:24 PM

It is an Event that belongs to any Actor. If you call "ApplyDamage" on an Actor then Event AnyDamage is going to be called.

avatar image rubiksmaster02 May 17 '19 at 11:41 PM

this is a new thing i got, it almost works how i need it to. it waits 10 seconds the first time its triggered instead of 5 and if its re-triggered then it waits less than 5 seconds alt text

capture.png (172.0 kB)
avatar image GarnerP57 May 18 '19 at 09:48 AM

You should not use Tick for simple calculations like health. Tick should only be used for things like movement. The two examples that we have given you uses timers and will only be called when necessary. Tick not only waste performance but can be tricky to debug.

avatar image Everynone May 18 '19 at 10:05 AM

Seconded. Spamming the latent request system with delays on Tick can be super hard to debug and just chugs memory unnecessary.

I'm pretty sure @DonBusso's solution would also work well here after refactoring so it does not depend on key presses.


@rubiksmaster02: You've got 2.5 solid solutions here with Garner's encapsulating a bit of additional functionality neatly.

But since you need to ask what 'set' is, perhaps it would be better to cover some of the basics first so you do not need to pull your hair out for hours.

On the other hand, everyone has their own favourite learning / failing method.

Good luck!

avatar image DonBusso May 18 '19 at 11:19 AM

As a beginner myself I know it can sometimes be frustrating when you spend a better part of the day trying to do something that in your mind should be easy but then you hit the wall again and again. Don't give up!

Have a look below. Copy and paste into your editor if you have to but this setup does work, maybe it will help you understand how basics work.

You will need to create a new blueprint class (actor). This will be a simple box collision actor. Name it whatever you want. When you walk into inside the box you will receive damage. You will see what I mean later.

alt text

Follow the steps in screenshots and then compile/save, place your actor somewhere in the world and you should get something like this.

alt text

Play with scale of the box in the world to make it big enough so it's easy to walk into, place it next to an object in the world.

Next go into your character blueprint and create some variables, you need 3:

Health (float) - to store your current health value, set default to 1. TakingDamage? (boolean) - to know if you are taking damage (default false) RegenUseTime (integer) - this is your clock value (default 0)

I'm using intager for my clock because I'm displaying the countdown on screen too.

alt text alt text

This may not be the best setup but I would say it's new-starter friendly. Of course solutions from @GamerP57 and @Everynone are awesome and way better then mine so you should give them a go too!

You have the solutions here, all you have to do is copy it and play around to better understand what is going on. Have fun! :)

alt text

avatar image rubiksmaster02 May 25 '19 at 10:11 PM

i already found a solution and it is way more simple than that you went a very long way around

avatar image DonBusso May 26 '19 at 08:23 AM

Great to hear you got it solved. Care to drop a few pointers how you dealt with the problem for newbies like myself? :)

avatar image rubiksmaster02 May 27 '19 at 02:22 AM

this is what i did,alt text health and health_check is 1

asasas.png (202.5 kB)
(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