Download

DetourCrowdAIController with custom movement controller

I have a custom C++ movement component that works great with the basic AIController. MoveTo and pathfinding both work as expected. However, pathfinding does not seem to work with DetourCrowdAIController, which is a serious problem.

I am not sure yet whether this is because I am using a custom movement component, or because of something else. However, when I make my custom BP class inherit from a DetourCrowdAIController instead of AIController, pathfinding stops working, so I suspect the custom movement might be the cause.

Do I need to do/write anything in particular to make my custom movement component work with a DetourCrowdAIController even when it already works perfectly with the basic AIController? If yes, what would that be?

In the worst case scenario(it just won’t work with my movement component), what would be a possible solution?

After reading the code for ADetourCrowdAIController and UCrowdFollowingComponent, I’ve inherited and overriden several virtual functions, like ApplyCrowdAgentVelocity and FollowPathSegment. Pathfinding works, but NPCs still bump into each other, so it’s pointless. I don’t see anything obvious that would make my class incompatible with the built-in crowd AI.

I would mainly like to know how to modify the set of waypoints the pathfinding subsystem calculates. Reading the code I have an idea, but the lack of documentation is questionable for an engine this popular. Still, at least I have the source code.

If everything else fails, I’ll resort to writing an implementation of boids, but I’d really like to make things work with the built-in crowd manager.

Hey man, I would like to ask if you made it work somehow? I’ve encountered a similar problem myself. I can’t seem to wrap my head around it. I’ve been trying for days but no luck. I might drop it after a day if I did not solve it, I’d go for boids too and the worst part is I’m using root motion for movement and I’m in too deep i can’t refactor my code lol.

I gave up on the built-in crowd avoidance. I made a few tests and realized it wouldn’t look good even if it worked, so I wrote a boids implementation. I considered group movement as well.

My game has a crowd of dozens of enemies pursuing the player at all times, all of which run towards the same general point. Without some form of crowd avoidance, the enemies in the back get stuck against the ones in the front when they surround the player, trying to push their way through. I realized I was trying to use crowd avoidance to make incomplete test AI work, so I made some better AI first and later realized simply applying a basic heuristic to push enemies out of the way, or telling the enemies in the back to wait, solved the issue for me. I decided to do this based on how similar games seemed to solve this issue. Turns out the simple solution works well.

The nice part is that it’s much faster than calculating crowd avoidance, so I can have even more enemies on screen.

Point is, do you even need it? Maybe you don’t.

That said, I did have a few plans to get it working. Firstly, if I absolutely had to get it to work as soon as possible, I would inherit from ACharacter instead of APawn, so that I can use the built-in movement component. My code would probably work with the default movement controller with only some minor changes.

My main strategy to solve this was to copy the engine’s movement component and path following component classes, renaming them to test, then selectively replace the code with my own until crowd avoidance stopped working, so that I can pinpoint exactly what the problem is. This may sound hilarious, but it works. You can try that if you have no other options.