Not using enough CPU resources Bug

Hello there. I’m running into an issue where seems that unreal isn’t using enough cpu. I have a machine gun and as soon as I start shooting my frame rate starts to drop. Having 40 bullets spawned is enough to make the game go from 120fps to 50-60.

It can not be a GPU problem because bullets has no graphic element, just the invisible in game scene component. Cpu can not be the problem because is to many fps loss if only added 40 bullets and it’s running on a i9-11k

Also, look the task manager and noticed that gpu and cpu usage are below 30% every moment, so the problem should be that unreal doesn’t use the needed amount of cpu.

You are spawning objects at at a high rate. Each actor needs to be constructed on spawn and memory allocated and be placed in the world. If your actors are de-spawning on collision then unreal also have to mark them for garbage collection and collect them at intervals.

Read up on object pooling or use ray / line casts to detect hits.

Actors have nothing but a scene component (default when creating a bp directly from actor class) and a bullet component, which is my custom projectile component which uses line traces to check for collision so all ready ray cast on movement

If you are spawning objects for bullets then you have to write your own object pooler or get one off the marketplace.

Ok. I’ll give it a try, know any tutorial from which I can take a look :question: Thanks

There aren’t any specific rules for poolers.

The pooler itself is just an actor with a TArray of type UObject or AActor
You set an int32 variable to the amount of objects (for instance 100 bullets)
in the begin play you go through a for loop and spawn all bullets up front and add them to the array.

Usually pooled objects would need an interface (eg. IPooledObject) with commands
Activate - initialize object
Deactivate - that let them return to the pool instead of destroying them.

During activation:

loop through the pooler array and check if an item has its active bool set to false, if so call the activate interface on it & break from the loop returning the new object

  • turning on their rendering, physics, could also be projectile movement component settings in the case of bullets)
  • their active bool is set to true

During deactivation:

  • their physics is deactivated and rendering and collision turned off.
  • their active bool is set to false
  • their position is set to the master pooler position

I have an old system somewhere buried in older projects I might be able to extract later on.

Just remembered I made an simple version of the pooler in bp not that long ago for a lidar project. It demonstrates the basics of the pooler.