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?

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).