0 votes

When I instance 200 rigid bodies in my game not colliding with each other as items the game fps drops to single digits, but the physics process stays at the same rate. I think there is a error I made because it should not have that kind of performance. How can I fix this?

rigidBody2d(The rigidbody's do not collide with each other due to layer settings)
-Sprite
-Collisionshape2d

I removed the Area2d with the collisionshape2d which made it able to go up to 500 rigidbodies before the fps drops down to single digits. It has something to do with the collisionshape2d in the rigidbody2d because if I disable the collisionshape2d there is no lag at all. If I reset the layers I could go up to 600 rigidbodies before lag.

asked Aug 9 in Engine by jujumumu (123 points)
retagged Aug 9 by jujumumu

If I'm not mistaken you already posted a similar question here https://godotengine.org/qa/49810/gdscript-is-being-slow
In order to help you, we need more details. Providing your project or a simplified repro would be best.

I did but the answers were not what I was looking for and the problem was not clear. What would be the best way to share my project with you? I do not think it is that my computer is struggling with rendering all of them. I think is because of the amount of collision pairs when there is 200 there is like 50000 collision pairs which probably leads to lag

Can you give somethings that would lead to this bug so I can check if I have them in my game

I can't, it could be quite anything. 200 staticbodies which don't touch each other should not make the game lag. Other people including myself have successfully tested with 1000 staticbodies having a sprite and a collision shape, without noticing any lag (and yet they were touching each other at that amount). Then you are talking about an Area2D but I have no idea what this one does. And yet, even without it, you seem to still have a significant lag.
We need the full picture, a project that shows the exact situation where that lag occurs, this way it is faster for anyone to find what's wrong rather than getting info bit by bit.
You can share your project using Google Drive if you have one, or a file sharing platform such as Framadrop. If it is too heavy, try to delete the .import folder.

First of all I made a typo it is rigidbodies not staticbodies. Staticbodies do not create collision pairs but rigidbodies do. When there is a lot of collision pairs the game lags. For my testing purposes I had all of the spawned at the sam exact place leading for each on to collide with everyone leading to really high exponential collision pairs. I am pretty sure the engine is working fine just that you are not supposed to have them all together in one clump. If I spread the out there is no more lag. In my game the items will despawn if left on the ground to long and 500 items clumped together is asking for lag.

So you solved your problem?

Ya godot is not built for having a lot of collision pairs which leads to lag. In my real game you should not have 500 items all clumped up together and they will despawn

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.