lag and frame rate drop , possibly because of function called many times in a single moment?

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

I noticed a stark frame rate drop of around 5, or a freeze of .1 seconds when I fired 5 separate projectiles (rigid body 3D’s ) at once to collide with an enemy which then instanced 5 separate “floating” damage number indicators near that same enemy. (sprite3D)

I did some testing and its not the instancing of the 5 rigid body projectiles that causes lag. Nor is it the collision with the enemy that causes lag. What causes lag is that when the projectiles hit a body they call a function in that body called: hurt(), which generates the floating damage numbers. I wondered if this lag happens because a function being called several times almost at the same time would cause lag? 5 times to be exact in milliseconds i guess.

Is there a better way to go about making a function that will be called many times at once without making my frames choke or hiccup? I made sure that my sprite3D’s view port into the 2d damage labels were rendering in 2D also.

Are you loading anything in these functions? Does the hurt() function load some nodes, or instance some objects at the collision?

Ertain | 2020-11-07 08:17

I am! I am instancing a sprite3D (with a view port texture to a label ) every time this function is called. I heard that Sprite3D’s have bad performance. I switched to a quad mesh with a view port texture and it was even worse so i switched back.

My other functions that instance things don’t lag nearly as much as this one does.

witch_milk | 2020-11-07 14:45

:bust_in_silhouette: Reply From: digitaldipak

What causes lag is that when the projectiles hit a body they call a function in that body called: hurt(), which generates the floating damage numbers