Defold game runs very slowly

I have read through a lot of posts around this topic but I cant understand why my game feels as though its running in slow-motion. Its getting low ms of ~10 and high fps (not sure exact number but easily over 60), and im pretty sure all the necessary code has dt used. Game gets progressively slower as I create more bullet game objects(created from a factory)


Ignore the terribly laid out work, first coding project basically ever.

Some Information that might help:

  • When Vsync is turned off in defold, game runs even slower than normal
  • Vysnc is usually set to off in my GPU settings but ive messed around with it on and off no matter what game still runs slowly.
  • Doesnt feel like anything changes when frame cap changed from 0 to 60 or higher
1 Like

To me it sounds like you might be a spawning issue.
Take a look at your profiling numbers and see if they make any sense.
E.g. how many game objects do you have?
What takes the most time during a frame?

2 Likes


This is alot higher than what I was got when I checked last time, this is when ive spammed bullets

This is the code inside the bullet game object that gets created from the factory if it helps

image

I think the reason of such behaviour is in on_input funciton.

Please, share this function as well.

Btw, you can paste code using this button:

I dont have anything in the on input of the actual bullet game object but this is the on input of the script that creates the bullets

function on_input(self, action_id, action)
	if action_id == hash("mouse_button_left") and action.pressed then
		

			component = "/bullets#bullet_factory"
			p = go.get_position("mainChar")
			local id = factory.create(component,p,nil,dire)

			msg.post(id, "fire")
			go.property("dire", direction)
			

			clickpos = vmath.vector3(pmx, pmy, 0) 
			pos = go.get_position("mainChar")
			clickpos = vmath.vector3(clickpos.x+pos.x - 640,clickpos.y +pos.y - 360,clickpos.z)

			direction = vmath.normalize(clickpos - pos)

		
	end	

	if action.x and action.y then
		--sets the values to mouse positions
		pmx = action.x
		pmy = action.y
	end
end

It looks ok.

I see you use many variables without local keyword which means they are global (maybe you have these variables in script as local, but I don’t have enough info to be sure).
Maybe it’s not performance issue, but if you use the same variables for bullets and player it overrides and make your moving sluggish.

1 Like

I went through and changed variables in most of my scripts to local, but the variables Ive used in the two scripts are different anyway. Not sure what else to try, if you have any other ideas they are greatly appreciated.