x

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"

AnswerHub Maintenance

Background maintenance is scheduled to occur between 9 - 11am EDT on Tuesday, May 21. Site operation may be slower than normal during this time and a brief interruption in operation may be observed

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.

Product Version: UE 4.20
Tags:
more ▼

asked Jan 02 '19 at 03:28 PM in Using UE4

avatar image

Abanoub-G
10 2 4

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

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!

more ▼

answered Jan 02 '19 at 08:21 PM

avatar image

the_batch
1.2k 4 5 8

avatar image Abanoub-G Jan 03 '19 at 09:33 AM

Hi, Thanks a lot for your help. Yes that is the problem. I have spent so much time trying to look for ways with which I can reference the AI character with and I just couldn't.

I can't manage to find the "TActorIterator" block and I am not sure how I can store the reference to the AI once the TActorIterator finds it. I would be really grateful if you can post on here a picture of a quick example of how you would do this via the event graph.

Thanks in advance.

avatar image the_batch Jan 03 '19 at 01:52 PM

Sorry, Abanoub-G. I must have had a brain spasm the moment I started writing about the TActorIterator. That’s how you do what I was trying to say using C++. We were talking about Blueprint scripting, obviously. Let me try again.

What I meant to suggest is the Get All Actors of Class node.

Using that node, you can find all the AI Character actors in the world and loop over them until you discover the exact one you want. Alternatively, the Get All Actors with Tag node might offer you a bit more utility, if you’d rather go that route. It works very similarly to its ‘of Class’ cousin node.

Hopefully one of those ways will get you where you want to go. And again, sorry for the earlier confusion!

avatar image Abanoub-G Jan 23 '19 at 05:14 PM

Hi, I now need to do the same thing but with C++, so can you please tell me how I can go about doing that. Note that my knowledge of C++ is very limited.

Thanks

avatar image Abanoub-G Jan 25 '19 at 12:05 PM

Figured it out use, simply use GetActorLocation();

(comments are locked)
10|2000 characters needed characters left
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