I’ve been working on a turn based game in which characters can perform actions just like X-Com. I’ve been implementing my game in C++ for easier code maintanance, refactoring and debugging…
And for the task I have at hand I am restricted from using the AI system (Behaviour Trees) of the Unreal.
For character actions (like move to a destination, attack some target, use some skill etc.) I’ve implemented a generic action management system which is based on a custom base class called UAction.
Whenever a character takes an action, an instance of a class derived from UAction (Say UMoveAction) takes control of the character. This action instance has access to the character’s ai controller instance, the pawn/character class instance and also its animation instance. And it makes the character perform the action at hand respecting the action type (Move,Attack etc) for which the derived UAction is implemented for.
Now my problem is I am trying to make the character move using Unreal’s path planning. For this I’ve figured out there is the MoveToLocation(…) method inside the ai controller class of the character (derives from AAIController).
I have generated NavMesh which I can display with “P” button. And Navmesh works without a problem for other parts of my code.
My problem is no matter what I do my characters always fail to move. Once MoveToLocation() is called, it returns success but it seems it immediately fails in 1-2 frames following the tick it is called. The characters briefly starts playing the move animation but then they immediately stop.
Here is the section of the code in UMoveAction which is responsible for moving the character
EActionResult UMoveAction::OnPerform_Implementation(FActionCost & performCost)
{
performCost.actionPointCost = 0.0f;
performCost.movementCost = 0.0f;
initialPathCost = 0.0f;
currentPathCost = 0.0f;
//Attempt to switch to able state if it fails return failure
if (!animation->SetState()) {
return EActionResult::FAILED;
}
//Unset any action montages that are set
animation->SetAction();
//Also unset upper body animation
//TODO: This may actually be set to an animation depending on characters current equipment
// i.e. a greatsword wielding character's upperbody will animate differently than a character with daggers when moving
animation->SetUpperBodyAnim();
EPathFollowingRequestResult::Type moveResult = ownerController->MoveToLocation(parameters.targetLocation);/*, acceptanceRadius, false, true, false, true);*/
//If a path cannot be generated from the nav system return failure
if (moveResult == EPathFollowingRequestResult::Failed) return EActionResult::FAILED;
//Else if we are already at goal return success with zero cost
else if (moveResult == EPathFollowingRequestResult::AlreadyAtGoal) return EActionResult::SUCCESSFUL;
//Else we are now on the path return inconclusive with zero cost
else {
initialPathCost = ownerPathFollowingComponent->GetRemainingPathCost();
return EActionResult::INCONCLUSIVE;
}
}
owner is a reference to the character to which this action is applied to. ownerController is a reference to this character’s ai controller and ownerPathFollowingComponent is the UPathFollowingComponent reference which is set in character’s ai controller.
I’ve tried MoveToLocation(…) with many different parameter combinations (commented out in code) but it seems none of them make the character move (more then 1-2 frames).
What might be the problem in this case? Could you suggest where I should look at to solve this?