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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

Changing target after first actor is destroyed

I'm trying to make a tower defence game but the problem is that if I build a tower and 2 actors come in the same overlapping range of the tower the tower will shoot the first enemy but the second enemy will be ignored. I'm checking which enemy is entering via begin and endoverlap. Does anyone have an idea how to fix this?

alt text

Product Version: UE 4.11
overlapping.png (220.9 kB)
more ▼

asked Jun 18 '16 at 10:26 AM in Blueprint Scripting

avatar image

3 1 2

avatar image RikBiggelaar Jun 18 '16 at 10:31 AM

A view while playing the game alt text

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

1 answer: sort voted first

When its done shooting the first target have it do a GetAllOverlappingActors, if you want it to prioritize at that point its kinda going to be up to you. You could do distance from tower to target, or if you have some kind of variable on the targets for how close they are to the end goal you could have it pick its target based on that. If you get all overlapping actors and there are no actors to attack then just have it sit there until one triggers the OnBeginOverlap again.

more ▼

answered Jun 18 '16 at 10:32 AM

avatar image

326 6 6 11

avatar image RikBiggelaar Jun 18 '16 at 11:07 AM

I tried doing what you said but its still inst working. This starts in the tick and if the Current Target inst valid(So no enemy is being targeted) it should check everything that is overlapping and set the first in his index as his new target. I'm not thinking about which it should select as enemy as long as it isnt checking any enemies at all :Palt text

update.png (158.5 kB)
avatar image MOS99Z Jun 18 '16 at 11:11 AM

I'll set up some BP logic for you to try out, give me a moment.

avatar image MOS99Z Jun 18 '16 at 11:29 AM

alt text Updated picture. Try something like this out and let me know how it goes.

avatar image RikBiggelaar Jun 18 '16 at 11:41 AM

It works perfectly! Thanks alot!!

avatar image MOS99Z Jun 18 '16 at 11:42 AM

Good to hear, don't forget to mark this as a solution. :D

avatar image MOS99Z Jun 18 '16 at 11:58 AM

Now as an optimization instead of doing this all based on BaseEnemy, you can set up the collider on the enemies to have a tag of Enemy. Then pull off the pin from Other Comp instead of Other Actor, check for tag Enemy and save the Other Actor ref as the current target. As well, instead of get all overlapping actors, you can get all overlapping components and check for the tag as well. Its best to avoid casting where you can, and this way the target doesn't even need to be a base enemy. Also I wouldn't normally put that stuff on event tick, instead I would do it on a timer by event for how ever often his attack speed or reload speed is. Also realized some of my logic wasn't 100% so here is an update.alt text

avatar image BarryMcCabe Jul 22 '17 at 10:12 AM

Seriously thank you for taking your time to show people how to do this efficiently.

(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