Fix unanchored part lag in Roblox with MeshParts

Zach Curtis
4 min readFeb 8, 2018

--

A large amount of unanchored parts in a Roblox game puts a tremendous strain on the physics engine, often causing visible ‘lag’ due to increased calculation times.

There’s a quick way to help fix this lag by utilizing MeshParts to lower the number of unanchored parts.

For this article I’ll be optimizing this jeep. With 324 parts in the model, having a few of these jeeps in the game at the same time will start to cause some lag.

Our starting part count is 324. Having 5 jeeps driving at the same time would be 1620 parts. This is quite a bit of parts for the physics engine to calculate.

Step One: Organizing all the parts by color

We won’t be creating a texture image for our mesh parts, favoring part color to save some time.

Because this would take a while by hand; I’ve wrote a quick script that does it for us. We don’t want our wheels to be included in this, so that we can later make them turn based on player input. I’ve also done this for the front suspension coils, and 2 decals in the rear.

Name any part “Exception” to cause the following script to skip over grouping this by color.

In a script in your game, paste the following in, and then change the property name ‘Jeep’ to your model’s name in workspace, then copy and paste the edited script into the command bar and hit enter.

After running the script; your model will look something like this:

Our jeep model now has parts sorted by color

Step Two: Exporting the color sorted parts as mesh .obj files

Exporting roblox parts and models to .obj mesh files is as easy as right clicking on the model or part, and selecting ‘Export Selection’

Exporting the model containing the majority of our jeep’s body.

Repeat this step for all of the color sorted model.

Step Three: Importing obj’s to MeshParts

Now that we have all our obj files exported from the color sorted models, we need to import them back into roblox. We will do this using the upload button in the MeshId property in studio, so we don’t have to upload obj’s from the site.

In a new MeshPart in studio;

The quick upload button in the MeshId property of a MeshPart

Use exported location data to quickly move and scale our MeshPart correctly.

You can optionally position MeshParts yourself; but we don’t need to

Roblox will merge the multiple objects contained in our obj file for us.

Name your MeshPart the same as the model it came from so you can easily keep track of it. Grab the color from your original model, and give it to the mesh part.

For every obj file you exported, copy and paste a meshpart and repeat this step.

Sometimes exports can have too many triangles making up their shape.

I ran into this with my roll bars and bumpers, caused by the large number of cylinders contained in them.

A bit over the limit on triangles for this obj.

This is easily fixed by cutting down the number of parts in each export. I had to seperate my roll bar and bumper, and then split both of them in half.

Step Four: Moving our exceptions to the meshed jeep

At the time of this writing; Roblox curiously inverts the location data during export and import. This is easily solved with a plugin that has a pivot feature, such as Studio Build Suite by Fractality

First you need to put a new part at the origin position of the game. Set the parts position property to 0,0,0

Then select all of your exceptions, plus seats in our case, and pivot rotate them by 90 degrees around the orient to line them up with the new meshed jeep.

Step Five: Admire your optimized model!

Ain’t she a beut’

We’ve managed to turn our 324 part jeep into 26 parts without much trouble, and it looks exactly the same.

This easy trick can help fix lag related to moving part count for anything from cars, planes, boats, to tools made out of parts.

--

--

Zach Curtis

Indie developer chronicling my adventures and things I’ve learned. Interested in game development on Roblox, web development, and machine learning.