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"

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?

Product Version: UE 4.9
more ▼

asked Nov 12 '15 at 10:47 PM in Blueprint Scripting

avatar image

225 21 29 91

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

1 answer: sort voted first

Hello UpARiver,

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.

more ▼

answered Nov 12 '15 at 10:54 PM

avatar image UpARiver Nov 12 '15 at 10:56 PM

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

avatar image Matthew J Nov 12 '15 at 11:03 PM

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.

avatar image UpARiver Nov 12 '15 at 11:07 PM

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?

avatar image Matthew J Nov 13 '15 at 02:50 PM

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.

avatar image UpARiver Nov 13 '15 at 03:31 PM

Thank you very much!

(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