Door Animation Slows Down The Game:

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

Hi,
I have three doors that are AnimationPlayer, and when I run the scene and try to open any door, the FPS fall from 60 to 3. After that, they return to 60. I am worried because this maybe will crash the game in mobiles. This is a 3D scene. I also tried to avoid collisions while animating, but it does not take any effect in the scene. The scene has got more animations but they work fine.
How can I fix this error?
THanks in advanced

How many frames are in the animation and how large is the door? (perhaps show a screenshot)

Amateur.game.dev. | 2021-07-14 15:56

The screenshot:

MxtApps | 2021-07-14 16:44

It might be because of all the CSG Meshes in your walls and door.

As they intersect they “create” a new mesh. What may be happening is that as you animate the door, every frame, the CSG meshes are recalculating their combined geometry.

Does the door need to be a CSG Mesh? Try replacing it with a basic MeshInstance and see if that changes anything.

Yuminous | 2021-07-15 02:48

It works, thanks.

MxtApps | 2021-07-15 10:00

That’s really great! I’ll put it in an answer so it can be seen as solved.

Yuminous | 2021-07-15 16:29

:bust_in_silhouette: Reply From: Yuminous

As per the provided screenshot, the door is part of a collection of geometry in the scene using CSG Meshes:

Scene Tree
Constructive Solid Geometry are meshes which can add or subtract from each other, but this is a calculation that has to be performed by the system, thus their unique feature may also severely degrade performance if modified at runtime.


In this case, as the door opens and closes it is intersecting the other CSG wall meshes and will be recalculating their combined geometry result on single frame, which resulted in the massive framerate drop as was confirmed.

This was solved by making the Door a regular MeshInstance.

Door and Walls

The solution to avoid this is to replace any CSG components that you are likely to animate (or which may freely intersect other CSG geometry) with MeshInstances.

While CSGs have their uses, they are unfortunately somewhat deceptively advertised as being the solution for level prototyping, when in almost all cases MeshInstances will do an equivalent job for basic level prototyping.

Anyway — while MxtApps has solved the problem, I hope that it helps anyone else!