Crowd simulation in ALS vs My Custom code

I don’t underestand one Very important question.

My Project

I have Third Person Template with custom Animation Blueprint, that has NativeUpdateAnimation event overriden with simple logic:

void UAnimInstanceBase::NativeUpdateAnimation(float DeltaSeconds)
{
	Super::NativeThreadSafeUpdateAnimation(DeltaSeconds);

	if (Character == nullptr || MovementComponent == nullptr) return;

	// all calculations go here
	GroundSpeed = Velocity.Size2D(); //UKismetMathLibrary::VSizeXY(Velocity);
	CurrentAcceleration = MovementComponent->GetCurrentAcceleration();

	//UE_LOG(LogTemp, Warning, TEXT("Speed: %f"), GroundSpeed)
	ShouldMove = (GroundSpeed > 3.f && !UKismetMathLibrary::Vector_IsNearlyZero(CurrentAcceleration));

	//UE_LOG(LogTemp, Warning, TEXT("Speed: %i"), (int)ShouldMove)
}

It’s the c++ realization of third person template’s default BlueprintUpdateAnimation event.

I made scene with 40 NPC’s without any logic or AI inside of them. Just simple NPC’s.

Each NPC on the scene has just Empty mannequin and c++ based anim bp.
No extra components, no tick logic, nothing.


AnimBP is very simple, it’s the one you get by “default” on ThirdPersonTemplate.

Now let’s have a look at my framerate on the scene.

It’s 20 frames per secong and Game Thread has 12ms of World Tick Time.


Only 20! Why do i got so BAD results with nearly empty scene?
“you can optimize tick rate blah blah”… No. With only 40 npc’s i even don’t have to.

Let’s look at this:

For free we have GitHub - dyanikoglu/ALS-Community: Replicated and optimized community version of Advanced Locomotion System V4 for Unreal Engine 5.1 with additional features & bug fixes
It’s c++ plugin of Advanced Locomotion. It’s totally free and can be used. I downloaded it.

ALS Community plugins scene has 42 NPC Characters with simple AI logic on Each! of them.
Logic of each character is very complex, including curves and other things…
Animations are complex, AnimBP very complex, just look at it.


AnimBp itself is parented to the c++ base, which has very complex NativeUpdateAnimation logics.

Yet, on ALC test scene, with 42 characters + AI i have 32 frames per second!

Conclusion

Why, on my very simple project i get 20 frames for 40 npcs, and on very complex ALS project i have 32 frames per second. It is Impossible!
Simple project should had bigger framerate results. I can’t belive results that i got. It is impossible. How on earth is this works. What is the secret of ALS that i don’t know?
“Update Rate Optimistaions” on each character? No, they are disabled. So Why? Why? I can’t get it.

i disconnected Control Rig and that gave me 1 frame…


as you can underestand 1 frame is definetely not the result that i want to see

in the end i think, it’s because rig complexity. Unreal Engine 5 Mannequin has Very complex rig with a lot of bones. Each bone should update itself each frame. And if you have many npcs on the screen before player, it will force all bones to update. This will drop framerate.
Reason, why ALS was faster is simple - als mannequin has simplier rig, old version from the Unreal Engine 4.

Conclusion: use simple rig in you need to simulate many characters at the same time without hiding them off.
This is important for strategy games.
Or just somehow awoid using rigs at all, just use … mechanical things or very simple rigs with 10-15 bones only. And ofc bake all morph targets if you have them.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.