My goal is to create a custom AI car from the sedan template.
The AI works fine when the player is controlling the car, but if another car is placed in the level, that car does not move. Debugging shows that all of the nodes are firing, but Set Throttle, Set Steering, and Set Handbrake nodes don’t function.
To reproduce the problem, create a new project with the sedan template, modify the blueprint so that on tick it sets the acceleration to 1, then create a copy of the car in the level. The possessed car will start accelerating but the unpossessed car will not.
Any help will be appreciated.
Are you relying on the auto-possess settings to give the player control over the cars? If you want the player to control one car or the other while playing you have to set the player controller to possess a specific pawn/car. You can do this in the level blueprint.
I’m using auto possession for the player to possess one car, and if I add a button press event to toggle the AI on the car then the AI works fine on the possessed car, but if it isn’t possessed and a run the AI events with something like begin play then it will not work. The car won’t move, even when it shows in the blueprint debugging that the nodes are firing. It’s almost as if Set Throttle doesn’t work if the car isn’t possessed, which doesn’t seem to make sense.
I tried this while I was googling a solution and it didn’t seem to work, the car still didn’t move.
I think it might be a bug with the engine and Set Throttle. There have been other people having problems with possession/unpossession and the vehicle doing strange things.
I found out this hard way and had to look in VehicleMovement source code (same goes for CharacterMovement). There is explicit checks in this component which will ignore doing any movement if controller is not set for the owner (i.e. pawn). The easiest way to deal with this is set followings for the pawn:
- Auto Possess Player: Disabled
- Auto Possess AI: Placed in World or Spawned
- AI Controller Class: AIController
Above will cause pawn not getting auto-possed by player controller but still you will be able to set throttle etc on VehicleMovement and pawn will respond. Note that this would not work is you set
Auto Possess AI: Placed in World which is default.