URGENT: Get AI Character Location
Hi, I think what I am trying to do is quite simple, but I can't get around a solution for it.
Basically I am trying to get the location of an AI character, which is obviously not the player character. I want to use the AI character's position to process something in my widget.
In other words how do I get the position of an AI character in my Widget event graph?
I know there is GetActorLocation, but this would get me the players location not the AI character one.
Would really appreciate a prompt reply.
Thanks in advance.
asked Jan 02 '19 at 03:28 PM in Using UE4
The GetActorLocation Blueprint node will get you the AI character's location if you plug in the AI Character actor as the target parameter.
So, actually the problem is, more specifically: how do you access the AI Character actor from within a Widget Blueprint owned by the player? That depends, but there are multiple ways.
One way would be to use a TActorIterator to loop over all of the AI Characters in the world until you find the specific one you want. You might want to perform this loop lookup just once when play begins, and store a reference to that target AI Character in your Player Controller or even the Widget Blueprint object — whichever makes more sense in your case.
Alternately, you could make the AI Character send a reference of itself to a more easily accessible object, perhaps during its BeginPlay event. For example, on BeginPlay, you could have the AI Character grab the first PlayerController and tell the PlayerController to store a reference to the AI Character using a custom Blueprint function.
If your game needs to support networked multiplayer, it may be preferable to have the AI Character register itself onto human-controlled Pawn actors instead of just a single PlayerController, since there will be more than one player, and PlayerControllers for other players are not accessible by connected clients anyway.
Again, the best approach depends on your game and your design. But, one way or another, as long as you can stick a reference to the AI Character you want in your Widget Blueprint object, then getting that character's location is the easy part.
Hope that helps!
Follow this question
Once you sign in you will be able to subscribe for any updates here