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"

Strange ForLoop Behavior

Hi, thank you for reading!

I'm making a tower defense game. I have a tower that fires a homing projectile to its target, hits, applies a brief stun, and does damage to enemys within a certain range. Everything works correctly when the projectile doesn't do enough damage to kill the target. However, if the projectile kills the target, then the area of effect damage applies in a strange way...usually only targeting every other enemy in range when it should be targeting all of them.

For example, the AOE damages enemy1, enemy3, enemy5, enemy7, when it should be damaging EVERY enemy in range (enemy1, enemy2, enemy3, enemy4, enemy5, enemy6, enemy7, etc.).

The picture listed shows how I cast to the enemy actors. I am baffled by what is occurring, any ideas?

alt text

Product Version: UE 4.12
lighttowerissue.png (205.8 kB)
more ▼

asked Mar 15 '17 at 08:23 PM in Blueprint Scripting

avatar image

241 8 9 12

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Yea thats what it was...I'm not exactly sure how the getOverlappingActors function works...maybe it fires every frame by itself, but having it plugged directly into the loop broke it. I had to set the getOverlappingActors function to a new array, then plug that array into the loop and now everything works. This seems redundant, but it works.

alt text

more ▼

answered Mar 15 '17 at 11:40 PM

avatar image

241 8 9 12

avatar image ExtraLifeMatt Mar 15 '17 at 11:44 PM

Weird, that seems like a bug.

(comments are locked)
10|2000 characters needed characters left

Have you tried placing a debug print statement if your IsValid check fails? I imagine TakeLightDamage may be queuing the Actor up for destroy and so the IsValid check would fail.

more ▼

answered Mar 15 '17 at 08:51 PM

avatar image

1.5k 33 13 48

avatar image samnater Mar 15 '17 at 11:20 PM

I just did as you suggested...didn't find anything useful from looking at the debug info for the blueprint, but maybe I was looking in the wrong spot? Its actually okay for the IsValid check to fail...the array it allows addition to is only used to later unstun hit enemies. So if an enemy survives the AOE, they will be added to the array and regain their movement speed later after passing another IsValid check to see if they are still alive.

If the IsValid check fails, is that somehow breaking the forloop? I would think it would fail the IsValid check, and loop back to the next overlapping actor...but it seems like its skipping actors

avatar image samnater Mar 15 '17 at 11:30 PM

Now I'm thinking it may be how the getOverlappingActors function stores items in an array--going to look at that

avatar image ExtraLifeMatt Mar 15 '17 at 11:31 PM

You are also checking the Healthbar for IsValid and not the Actor itself. I wonder if it's silently failing that and causing some internal script assert. I've had Blueprints that act too well behaved when things go wrong. You may want to add a check to the Target after the damage is applied and not just Healthbar.

avatar image samnater Mar 15 '17 at 11:42 PM

Thanks Matt, you helped me get to the answer!

(comments are locked)
10|2000 characters needed characters left
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