Casting to enemy Pawn from Player

I am trying to cast from my Character to an enemy to check a boolean, so I make a cast to Enemy. However I don’t know which object I should get, I tried get controller, get controlled pawn, none works. Which one should I use?

It’s happening in a InputAction. What do I do? Thank you very much for helping out :smiley:

I will have multiple of them yes. Do I still have to do a linetrace if I want to simply check if a boolean from the enemy pawn is true or false?

Hello ,

What type of event is this occurring on? Depending on what is happening at the time, you could do this in multiple ways. One example would be if you were doing an EventHit or EventOnBeginOverlap you could use the OtherActor pin to cast.

It depends honestly. Are there multiple instances of your Enemy? If there is only one, this can be done easily by using a Get All Actors Of Class node and setting the class to your Enemy’s class.

If there are multiple and the player must be looking at the enemy that this boolean needs to be checked on when the InputAction is fired, you could use a line trace from the character to the enemy. In the event of the line trace touching an enemy, it’ll output a “Hit” which you can pull off and use a “Break Hit Result” node to get all of the details of the hit, including the “Hit Actor” pin.

The line trace is used to get a reference to the particular Enemy that you’re aiming or looking at. If the line trace intersects with an Enemy (You can set up a specific Collision Channel for your enemy and do a Line Trace By Channel), it’ll return a Hit struct, which will contain a reference to that Enemy in the Hit Actor pin.

Thank you very much!