I would like to check a variable ( isSoldier? ) on a NPC character through a line trace. Then I would like to keep track of this NPC’s position until there is another line trace to a different NPC, in which I could repeat this. There is never collider overlap or contact other than the line trace. The NPC’s spawn and are later destroyed (killed).
Basically I need to get a reference to NPC for BP communication, store it, use it to track the NPC, then replace the reference with another NPC and repeat.
I have tried getting the hit actor from the trace and cast to character, then promote to variable to get the reference to the NPC so I can communicate info back and forth, but cant get it to work.
Any help or advice would be greatly appreciated.
Thanks!
Using this I can track the position of the traced NPC (function shown disconnected).
But I cannot get a public bool “isSoldier?” from it, nor can I set any variables on it.
I am trying to come off the “Char Ref” pin to do this. Maybe I am on the wrong track?
Character is the default character class, most likely. You will want to cast to the derived one instead, the one you’re using. What is the name of the blueprint that has the isSoldier variable - cast to that instead.
Thank you, that works!
However it is not reusable for another NPC, as I dont know which one has been caught by the trace, I wouldn’t know the one to cast to. Maybe sorting an array? sounds expensive.
Is there another way to do this? to get/set variables on the raycast hit NPC?
Following your advice, I briefly looked at BP interface communication, it appears it will work with raycast, I always thought you had to have overlapping colliders for it to work.
I really, really appreciate your time in helping me out!
Thank you!