Is it the case I should move to c# from gdscript?

Godot Version

Godot 4.3

Question

I hit a performance issue recently. After some investigation, I think it may be the performance of gdscript. Here’s the brief:

  1. Without any gdscript attached or nothing in _process(delta) for the node, I get FPS around 300 after spread 1000 of a simple mesh onto the main scene (there’re some other stuffs in the scene but doesn’t matter as they’re always there in all the tests)
  2. Add a simple line in the gdscript to make mesh rotating on Y axis. The FPS go straightly down to 40.
  3. So my first thought is I should not do this simple rotation in script. The only viable option in my knowledge is using animation. I deleted (unattach) the script and add an AnimationPlayer, then add a track to animate to rotation. Now the FPS is around 50 which is not an gamechanger.

So the questions are:

  1. Is there any other way to improve the performance for a simple transform? For example, using physics engine (I mean use rigidbody with all collision disabled, set an angular velocity then leave all the work to the engine) to do the job? I haven’t tested but I’m not sure it’s a good idea as the physics engine have a lot of overheads but all I need is just a rotation for this node.

  2. If not, should I look for replacing the gdscript with c# as it’s complied? I’m reluctant on this solution as the whole project is written in gdscript but since godot support mixed languages so I’m fine with one or two simple c# class.

I remember some senior friends here said the key of such performance issue is to reduce the calls between script, no matter gdscript or c# class, and the engine. It makes sense but I have no idea how to do it in this case.

Thanks!

I found the problem. The ‘simple’ node is not actually simple. It contains a lot of other meshes even they are not visible (flag is turn off). After I replace it with a real simple one, the FPS is increased dramatically.

It confused me at the beginning as the rotation script did make difference in tests. So the lesson to me is that the mesh/triangles got transformed still consume lots of resources even they’re not visible.

1 Like