SOLVED: Missed a property: CollisionEnabled. It was set differently in my BP and native class… Appreciate all the help and advice.
TLDR: Super simple class connected in BP then written in C++, exactly the same, when run, the C++ class takes twice as much CPU time as the BP class. Performance & profiling is not the topic(fairly welcomed though…)
Hi, I was trying to mimic a fish horde in UE4, and when the number goes up, I pretty quickly hit the CPU game thread bottleneck. At 1500 fishes, I get 40+fps, barely, rendering once (well it was intended for my vive…) The game thread takes roughly 20ms which is also the frame time, according to “stat unit”.
Suddenly I remembered, some Epic employee posted that C++ could be 10x faster than BP, and I’ve been meaning to practise my coding skill, so I manually converted everything (really just a spawn volume and a fish…) to C++ and crossed my fingers and hit play… The spawning process, which was short and green (fps) with BP, went up to 100+ms/red… And when the fishes are spawned and swimming, the game thread goes up to 40~50ms, still matching the frame time, still the bottleneck.
Then I did a stat start/stopfile on both version and compared them, turns out in both version, “ProjectileMovementComponent” under WorldTick is taking the most time. In BP the ProjectileMovementComponent is taking 7.5ms while 18ms in C++; WorldTick takes 11ms in BP while 28ms in C++…
I guess I must be doing something wrong, but it’s so simple and same as the BP, I simply can’t find it… Here’s how my fish class works:
Basically it’s a homing projectile set to follow an empty actor which will be moved by a level sequencer.
A static mesh component attached to a scenecomponent which is the root. A ProjectileMovementComponent, of which the “IsHomingProjectile” is set to true and the homing magnitude is 200.f.
In the ctor, I set the MaxSpeed of the projectile to a random float between 600~1000.f.
In beginplay I do if (TargetActor) { ProjectileMovement->HomingTargetComponent = TargetActor->GetRootComponent(); }
But I don’t suppose these matter midgame… And in tick, I simply check the movementcomponent’s Velocity.Size() and SetVelocityInLocalSpace(FVector(200.f, 0.f, 0.f)) if that size is <= 10.f. I even set the static mesh in C++ for maximum efficiency…
The BP is setup exactly the same, and it’s just so simple that I can’t figure out why…
Seriously, any help is appreicated…