How to detect an actor in a vector?

I’m searching for a way to detect an actor in a vector but I can’t find anything to help me.
I wanted to do a function which makes my character hit an ennemy in front of him. To do that, I try to create a vector starting from him (when he strikes) and if an actor (an ennemy) is detected in the vector, I call an other function (for the damage). But I don’t see how to make the detection in my code with a form like :

if (actor in vector)
actorTouched = actor;

If someone can help, thanks.

I’m going to assume you mean in a TArray: You’re looking for the Contains member function.


if (Array.Contains( actor ))
1 Like

What you’re looking for is a trace. You can use any of the trace functions in UKismetSystemLibrary, such as LineTraceSingle, or perhaps BoxTraceSingleForObjects depending on your preference, and if you want to have a very accurate trace or some lenience. If you’re using blueprints, you can also use the same functions, for example:


Oh, man I totally misread that question somehow. I got so stuck on trying to parse “in a vector” which didn’t make any sense to me.


Hello, I watch some documentations about LineTraceSingle, it works perfectly. Thank you for this. :slight_smile: