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. 

Destroy different Blueprint Actors with overlap

Hello I'm learning Unreal and made a basic thing where I press F to shoot a bullet, when it overlaps an enemy the enemy is destroyed. I'm wondering how would I destroy different types of enemies? Currently since there's only 1 type of enemy this works, but I can't figure out how to destroy different actors depending on which my bullet overlaps.

Apart from EnemyBP, in the future I would have Enemy2BP, 3, 4, 5, Boss, etc.

alt text

Product Version: UE 4.19
more ▼

asked Dec 04 '18 at 07:46 AM in Blueprint Scripting

avatar image

9 1 1 4

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

2 answers: sort voted first

there are many ways to solve your issue. first you could use inheritance so all your enemies inherit from the same class then you could cast to the parent class. by doing this the cast will succeed even for the child classes. another option would be to use tags, for this method you add a tag to every class you want to be able to destroy with a bullet then on overlap check to see if the other actor has the tag. the last option i will mention is to abandon the destroy actor in the bullet and instead have the bullet apply damage, this way only actors which you designate as being able to take damage will be affected. you could combine this with inheritance which would make it so you only have to make the script once in the enemy. the script itself would look something like (in bullet) on overlap -> apply damage, (in enemy) event any damage -> destroy actor. this last method is the one i would go with as it adds a greater range of functionality to your bullet, is easy to create and customize for each enemy type, and ive always found it to be good practice to have scripts that affect a actor self contained. then again this method may not be best for your add score system.

oh and on another note the way you have your set player score is not a good way to go (id be surprised if it works). you would be better to drag off the cast you have and search for get player score as you did for the set.

more ▼

answered Dec 04 '18 at 02:57 PM

avatar image

10.1k 33 10 23

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

You can set one and the same interface event in every actor, and call the interface message inside the bullet BP for the actor the bullet overlaps with. This way you won't have to Cast, and if any actor does not implement the interface that you call, nothing happens.

Since you might have lots of bullets flying at the same time, I'd suggest not using tick. You can set bullets to simulate physics, disable gravity, and just set an initial velocity for them.

more ▼

answered Dec 04 '18 at 07:56 AM

avatar image

1.8k 12 7 8

(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