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"

How do you use AIcontroller MoveToActor in a character?

Trying to make an AI Character move to my player character with the MoveToActor function. Don't know how to give the function to the AI character. Spent a few minutes trying stuff and got this. Player character is DCharacter, Ai character is DEnemy and DEnemy has AIController.h included

         AAIController* controller;
         ADCharacter* player = Cast<ADCharacter>(player);
 
         controller->MoveToActor(player);

this gives me the error: Error C4700 uninitialized local variable 'player'(and 'controller') used but the code doesn't have any red marks. was I close or am I completely wrong?

Product Version: UE 4.17
Tags:
more ▼

asked Apr 24 '18 at 08:29 AM in C++ Programming

avatar image

GoodNewsEvery1
5 2 3 5

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

1 answer: sort voted first

From the context you're giving, i can notice two things:

  • Your controller variable (controller) is not initialized, and it should be, with a function like "GetController()". When you call the MoveToActor function, you're calling it on a pointer that isn't initialized, and is therefore a nullptr.

  • Your DCharacter pointer is also a nullptr, because you're using the exact same variable for the cast, which is also not initialized, and you should give the cast a valid reference to the player you want to move towards (you'll have to find out a way to pass that reference to the AICharacter class).

more ▼

answered Apr 24 '18 at 09:23 AM

avatar image

goncasmage
897 12 14 25

(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