UCrowdFollowingComponent 51st bot does not move

I recently changed my AI so that the AI uses the Detours system instead of RVO avoidance that constantly pushed them out of the map. The problem is that this is being used on a whole bunch of light weight AI and only the first 50 actually move. the goal is to have closer to 300-400 ai moving along a path avoiding each other while attacking enemies. Is there somewhere I need to set the max number of AI that I didn’t see?

Hi ,

The 50 agent limit is hard-coded into the CrowdManager constructor. If you look in the source code, you can adjust the MaxAgents variable to increase the limit to meet your needs.

Alright thanks but that brings up a bit of an implementation problem. I’ve made a subclass of CrowdManager and in the constructor changed the max agents.

It looks like the Crowd Manager seems to create itself as a singleton. Is there a way to make my new crowd manager the default crowd manager without modding base engine code. It seems that the only interaction the UCrowdFollowComponent has with the manager is through the UpdateCrowdAgentParams() function. and that’s not virtual so I can’t override it.

I reached out to a developer who worked on the CrowdManager, and he said it would actually be easier to change the value directly in the source code, or to make it a config property (which is what we will most likely do eventually). Currently, you cannot easily substitute the crowd manager in your project since it needs to be created by the navigation system.

If you want to use your own subclass of CrowdManager, you would have to do the following:

  1. Create your own subclass of UNavigationSystem.
  2. Open Engine.ini and enter your subclass into NavigationSystemClassName
  3. Override CreateCrowdManager() in your Navigation System.
  4. Inside CreateCrowdManager, use the line SetCrowdManager(NewObject(this));
  5. Initialize MaxAgents in the constructor of your Crowd Manager

Step 4 assumes that your Crowd Manager class is named UMyCrowdManager.

Does it have to be in Engine.ini or can it be in DefaultEngine.ini located within my project folder. We are trying to avoid modifying the base engine in any way until the alpha is completed since that will be before the next release.

I have tried adding

[/Script/Engine.Engine]
NavigationSystemClassName=ShadowHeroesNavigationSystem

but the engine just crashes saying:

!Id:55bfa65478e1811c84f5e0c1e2da7d3c

Unknown exception - code 00000001 (first/second  not available)

Assertion failed: Class [File:D:\BuildFarm\buildmachine_++depot+UE4-Releases+4.4\Engine\Source\Runtime\CoreUObject\Public\UObject\Class.h] [Line: 2479]
ConstructObject called with a NULL class objec

KERNELBASE + 37901 bytes
UE4Editor_Core + 3095292 bytes
UE4Editor_Core + 1661738 bytes
UE4Editor_Core + 1541824 bytes
UE4Editor_Engine + 9642623 bytes
UE4Editor_Engine + 9761520 bytes
UE4Editor_Engine + 9431218 bytes
UE4Editor_Engine + 9438825 bytes
UE4Editor_Engine + 9335277 bytes
UE4Editor_Engine + 9004643 bytes
UE4Editor_UnrealEd + 1708367 bytes
UE4Editor_UnrealEd + 1700548 bytes
UE4Editor_UnrealEd + 5772394 bytes
UE4Editor!FEngineLoop::Init() + 526 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.4\engine\source\runtime\launch\private\launchengineloop.cpp:1871]
UE4Editor_UnrealEd + 5627284 bytes
UE4Editor!GuardedMain() + 285 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.4\engine\source\runtime\launch\private\launch.cpp:125]
UE4Editor!GuardedMainWrapper() + 26 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.4\engine\source\runtime\launch\private\windows\launchwindows.cpp:125]
UE4Editor!WinMain() + 249 bytes [d:\buildfarm\buildmachine_++depot+ue4-releases+4.4\engine\source\runtime\launch\private\windows\launchwindows.cpp:201]
UE4Editor!__tmainCRTStartup() + 329 bytes [f:\dd\vctools\crt\crtw32\dllstuff\crtexe.c:618]

Is there any particular reason for this hard-coded limit of 50?

It looks like AnswerHub removed a piece of my post. It may be what is causing your error message. In Step 4 that I mentioned above, the line of code should read:

SetCrowdManager(NewObject<UMyCrowdManager>(this));

Please let me know if that does not clear up the crash you are seeing.

Yea I looked at how the function was originally called and figured that part out. Knew it had to do it.

SetCrowdManager(NewObject<UShadowHeroesCrowdManager>(this)); 

Is the default engine entry correct when I put NavigationSystemClassName=ShadowHeroesNavigationSystem

It looks like it simply can’t find a class so maybe I have the ini file incorrect. It functions fine if I leave it at the default /Script/Engine.NavigationSystem

The information I was given was that it should go in the /Script/Engine.Engine section of the Engine.ini file. I will see if I can get some clarification of that.

Hi ,

CrowdManager and DetourCrowds were initially set up for use in Fortnite, and it seems that 50 was a good maximum number for their needs, so that was what they went with. You can scale it up or down depending on what your own project needs, though. Keep in mind this one portion of the comments in DetourCrowd.h:

- Crowd management is relatively expensive. The maximum agents under crowd 
  management at any one time is between 20 and 30.  A good place to start
  is a maximum of 25 agents for 0.5ms per frame.

I was able to get some clarification. The .ini file you want to edit is the DefaultEngine.ini file specific to your project. The edits also should be made in the /Script/Engine.Engine section of the file. That is where the class name is read from if one is specified, and is where the setting is made for Fortnite.

Was I understanding correctly when you said that placing the edit in the /Script/Engine.NavigationSystem section works fine for you?

Almost but not quite. It looks like my ini file is correct unless there needs to be a path to the class I’m using.
I have done my edits in DefaultEngine.ini This is what I added for the crowd system:

[/Script/Engine.Engine]
NavigationSystemClassName=ShadowHeroesNavigationSystem

That causes a crash when I launch the editor though.

If I change it to the default that is inside the BaseEngine.ini file it’s fine.
That would work like this:

    [/Script/Engine.Engine]
    NavigationSystemClassName=/Script/Engine.NavigationSystem

My problem is that when I try to use my nav system, it seems that it can’t find the file (at least that’s what I think is happening).

Given that I have not heard back in quite some time I may have to resort to creating my own crowd manager. The current one works for MVP but it will need to be updated in the future and likely optimized for larger numbers of units performing simpler tasks.

Hi ,

I apologize for the delayed response. I completely lost track of this post.

Give this a try in your DefaultEngine.ini file:

[/Script/Engine.Engine]
NavigationSystemClassName=/Script/<YourProjectName>.ShadowHeroesNavigationSystem

This format allowed me to open the project in the Editor, though I have not tested to see if the project actually uses the correct navigation system class.

Patch for adding settings of CrowdManager to config file: https://github.com/EpicGames/UnrealEngine/pull/655