Cannot add movement input to AI pawn not possessed by player?

I’ve tried adding movement input to a pawn that has an AI controller and behavior tree via the pawn, AI controller, and behavior tree, but it doesn’t seem to work anywhere. It will work when the player possesses it, but I don’t want the player to possess it, this is for an AI enemy. Is there no method or setting that will allow it to accept an input vector without being possessed?

I want to be able to have the max speed/acceleration/deceleration advantages of the movement component (that I added via ‘add floating pawn movement’ and do have access to-it’s not a matter of it not getting the component correctly). The ‘move to’ actions for AI will not accomplish what I need, and I don’t want to have to manually set its location or use force/velocity to control its movement. It’s incredibly frustrating for this action to seemingly be locked by the engine for no beneficial reason behind the requirement of being possessed by a player.

If you know of any way I can get the movement input necessary for my AI to be registered correctly I would be incredibly grateful as it’s an integral part of my AI movement design.

Movement components cannot be added to pawns - whether that’s an AI or otherwise. Try recreating a separate test version of your AI that’s based on a Character instead of a Pawn and you’ll get the control you desire.

Movement components can be added to pawns. My player is a pawn and I use a movement component I’ve added to that, and as detailed in the original post I can successfully get/read that the movement component on the AI is valid but it only acts as intended/receives input when it is possessed as a player.

You may need to disable/enable input on the pawn itself. Also, check the class defaults if “Block Input(s)” is enabled. If it is, uncheck it.

Regrettably that wasn’t it. It wasn’t disabled in there (I had checked there first with my own tests), and I’ve also ticked ‘force input’ in the add input vector node so it would ignore that and add input anyway if it was working. The only thing that has allowed it to function is possessing the AI pawn, but of course that doesn’t work when you want to possess the player and have many AI pawns/enemies.

Why didn’t you create it as a character intead of a pawn?

Because the character controller is awful for anyone like myself wanting a custom actor setup (character’s forced to have a capsule component>skeletal mesh, you can’t delete those) and the character movement attached is even more restrictive than the floating pawn component I’ve added.

Any news on this?

try adding “add movement input” in your pawn and write a BTT for passing the values / calling those functions from your ai

it doesn’t work

Sorry for necro, but this is the only thread that comes up on Google, so I’ll post an answer. I was trying to make an unpossessed Character walk through AddInputVector.

Necessary changes:

  1. ACharacter::IsLocallyControlled() must return true.
  2. Rewrite UCharacterMovementComponent::PhysWalking in the two places where it checks for CharacterOwner->Controller.
  3. I also had to set Movement Mode to Walking explicitly on BeginPlay, because it was NONE for some reason, but I didn’t dig into that.

Both of those two functions are exposed to be overridden in a child class, so no fiddling with the engine is necessary.

Note that if you plan on making your character move in different modes, you may also need to rewrite PhysFlying, PhysFalling, PhysSwimming, etc…

Another two avenues of approach I considered:

  • Allow PlayerController to possess multiple pawns. Some of this stuff wasn’t virtual, so I didn’t go there.
  • Use an alternative movement component, such as General Movement Component on the Marketplace, if your funds allow it. But it’s a bit of an overkill for my needs.

If I run into problems with my current approach, I’ll come back and let you know.

1 Like

Did you just make a C++ CharacterMovementComponent, copy and paste the c++ of PhysWalking, then rewrite the section it checks for CharacterOwner->controller?

Yes. Also create your own ACharacter class that overrides IsLocallyControlled to always return true.
And make this class use your new MovementComponent in Blueprints.