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 best to check overlap for more than one actor?

So I have a bullet, and I want it to destroy itself if it hits any of these 5 specific actors. I know how to cast to 1 individually, but not how to fire the overlap if it hits any 1 of 5.

Product Version: UE 4.20
more ▼

asked Nov 09 '18 at 02:22 AM in Blueprint Scripting

avatar image

11 3 6

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

1 answer: sort voted first

if the other actors are of a similar type you could have them inherit from one parent actor. or you could use tags to identify them, use the actor has tag node in this case.

more ▼

answered Nov 09 '18 at 02:26 AM

avatar image

10k 33 8 23

avatar image xGameSlave Nov 09 '18 at 02:52 AM

Can I retroactively have them inherit from a parent as child actors? And if I use tags, how do I cast to "any actor with tag" to overlap?

avatar image ThompsonN13 Nov 09 '18 at 03:00 AM

Can I retroactively have them inherit from a parent as child actors?

yes you can by going into the class settings and changing its parent. though it can mess some things up if theres other inheritance dependencies that you dont take into account.

how do I cast to "any actor with tag" to overlap?

you dont. as stated above you would use the actor has tag node. the "actor has tag" node basically just checks if the other has the tag your looking for. a cast just compares to see if the class you feed it is like another. in your case you dont really care what the other class is specifically as long as it has the tag. put another way lets say the actors with tags are the ones that can be damaged, you dont care what your damaging you just care that it gets damaged. ill post a picture below that shows what i mean.

in the example i set it up so on overlap the bullet checks if the actor it overlapped had the tag aka does the bullet care about the other actor. then we use a branch to control the scripts flow, if the actor has the tag cool we damage it, if not we dont care and do nothing.

alt text

capture.png (83.7 kB)
avatar image xGameSlave Nov 09 '18 at 03:13 AM

There is one more step i need to do, The actor that it just overlapped, how do I get the location of that actor specifically so I can teleport to it?

avatar image ThompsonN13 Nov 09 '18 at 03:23 AM

you just drag off the other actor pin and search for get actor location which will provide you with that actors world space location.

as for the teleport itself that depends on how you want to implement since theres a ton of ways to accomplish it. the most basic way to teleport would be: get player character -> set location (from within the bulllet). you could also control the teleport in your player. and or have a variable reference in the bullet to the one that fired it which may be good for multiplayer.

avatar image xGameSlave Nov 09 '18 at 03:35 AM

What if I need a certain component on the actor (but they are named the same on each actor)

avatar image ThompsonN13 Nov 09 '18 at 04:00 AM

getting a specific component isnt what you were asking for, you actually hadnt mentioned that at all. really it depends on the situation, im sure you could cobble together a system that uses a interface to exchange references and check if a particular component was hit but it wouldnt be very modular or well organized. or if you had inheritance on your side you could get the parents components but anything specific to the child would be difficult.

try explaining your situation and the context so we can understand what your trying to achieve. that way we can provide a more specific recommendation and have a more similar thought process to you.

avatar image xGameSlave Nov 09 '18 at 04:10 AM

Ok. So I am making this sidescroller action game, and in it there are five different enemies. The player has an ability where he will be able to aim in a 360 degree arc a beam (made up of constantly shooting projectiles that destroy themselves after passing limited range). What the projectile does, is that if it collides with one of the 5 actors, it spawns a teleport anchor, and the player can then use the teleport ability to move there. It is setup so that the anchor destroys itself if the player is missing.

This BP is for the projectile, which needs to only respond if it hits the center of the enemy character, because some of them have collision boxes used for sight that are fairly large. The issue now is that with the above code, with projectile immediatly despawns because it is registering a hit with the enemies vision range, not the mesh of the enemy itself.

avatar image ThompsonN13 Nov 09 '18 at 04:49 AM

got it! thats a much clearer image of your goal. one more question are all the 5 actors characters? if they are then its easy you just cast to the character class, then again if it were that easy you probably would have done that by now. how about creating a custom collision channel? or you could use the on component begin overlap node which will allow you to get specific components of the target actor. or use both.

i actually dont use tags much so i didnt realize theres a "component has tag" node, i believe you can use this node in conjunction with the on component overlap to get the result you want. you would just need to give the main body of the actor the right tag. i havent tested this and dont have time at the moment so its just theory but i dont see why it wouldnt work.

alt text

capture.png (62.7 kB)
avatar image Nebula Games Inc Nov 09 '18 at 03:12 AM

Alternatively you could use the very efficient "interface" system. So in each of your actors on overlap just have them fire this logic off. And in the "bullet BP" implement an interface that destroys the bullet. This way you can have many actors destroy the bullet and they don't necessarily have to inherit from the same parent. This will give you the most flexibility moving forward as they would just call the interface on overlap and not have to worry about what actor overlapped the bullet.

alt text

(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