Low framerate with just 60-70 moving nodes

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gargarensis

Hello everyone,
I was trying to debug my code where some units could move and attack because with around 60-70 units it started to run at a very lwo framerate.

Sadly, I commented out most of my code and discovered that it was still running very slow with only the movement inside the units physics process.
To make you understand better, here is the code and the profiler:

func _physics_process(delta):
  if self.isDead:
	  return

  if isMoving: # always true, since I commented the part of the code that could set it to false
	  var vector = ( self.destination - .get_global_position()).normalized()
	  myUnitBody.move_and_slide(vector * movementSpeed)

I was not able to understand why, with just that code and 60-70 nodes, I get this huge frames drop while I’ve read of people that manage to fit 500+ units without any issue.

Thank you in advance.

What kind of node are these units? KinematicBodies or something else?

omggomb | 2020-04-06 13:55

They are KinematicBodies with 2 areas, an healthbar (which is a subscene) and a CollisionShape2D

Gargarensis | 2020-04-06 14:21

Try commenting all the code inside the _physics_process method, then try uncommenting lines slowly.

Calinou | 2020-04-07 12:55

What processor do you use? I can imagine something like a 2014 mobile Celeron not being able to handle this many nodes.

MatteoKip | 2020-04-07 13:48

I am using an Intel Core i7-4510U

Gargarensis | 2020-04-07 16:45