#I need to add_child 10000 CollisionShapes to a Staticbody, but it's laggy.

14 messages · Page 1 of 1 (latest)

wind girder
#

I'm making an editable generated map, and everything works but if it gets too big the add_child() function gets laggier and laggier. This is really not going to work for a multiplayer game if the loading screen takes ten minutes.
The biggest a map is probably going to be is 100x100, which means I need to generate 10000 CollisionShapes, one for each tile. The reason I'm only having one each tile is that when editing I don't want to have to re generate all collision, just the tile and the surrounding tiles.

This is the laggy code I'm dealing with:

convex_shape = ConvexPolygonShape.new()
$StaticBody.add_child(colsha) #-> Very Laggy
colsha.set_name(str("COLLISION_X_", x, "_Y_", y))
colsha.set_shape(convex_shape)```
I don't know what to do.
wind girder
#

I need to add_child 10000 CollisionShapes to a Staticbody, but it's laggy.

#

I figured out it's the add_child that's laggy, not the new()

south ledge
#

You may have to use the physics engine directly like in bullet hell games. Just look for tutorials it's not something i have used

timber niche
#

Generally you don't want to have so many collision shapes. You'd probably want to combine some together, probably in some chunk size

wind girder
#

I'm currently on 3.5, but when I turned on GodotPhysics it was almost instant.

#

I'm currently undergoing the long process of converting to Godot 4 so that I can have full GodotPhysics
Unfortunately I have to rework my multiplayer implementation, fortunately the project wasn't very big yet.

torn elbow
#

You can consider disabling collisions that aren't necessary

rose sphinx
#

Once I did same with 2d tile map, C++ and Box2d physics - every tile had own collision body. It worked, but consumed 2Gb of Ram. Now I think that was wrong idea.

torn elbow
#

you can consider baking collisions

wind girder
south ledge
#

then dont use add child, its not needed

wind girder
#

Switched to godot 4, all problems are fixed

cloud timber
#

that's good to know. I load thousands of collision triangles in my game as well. I just load 25 per frame and have them load over time