How do I reduce memory usage when using CSG?

For over a year now, I’ve been searching for new ways to optimize my game. One of my goals has always been to reduce the amount of crashes on Mobile devices. Possibly the biggest issue I’ve encountered is a result of unions.

In the following picture, I’ve shown the amount of place memory being used when playing this game.

Memory_DevConsole

Over 1GB of memory seems a bit excessive.

This past Saturday, I added a pokemon called Lanturn into my game. A picture of the model we created for it is shown below:

While it does look amazing, this single model requires 4+ MB of memory. The biggest reason for this is because of how we’ve set up unions. At this point in time, Roblox doesn’t support directly changing colors on a multi-colored union (with UsePartColor disabled). To combat this, we set up unions as shown below:

What could be a single union is split up into several unions with UsePartColor enabled. While this does work, it significantly increases the total triangle count and the amount of unique unions.

The goal is to have each custom character separated into limbs (i.e. parts bound to a Torso versus parts bound to an Arm) while also having the ability for the colors of the parts to be freely chosen. This issue would be easily circumvented if we had the ability to directly change the individual colors on multi-colored unions without separating the union, as proposed in this post.

Are there any tips or suggestions on how to decrease the amount of memory being taken up?
Thanks!

4 Likes

Well there’s the obvious one: Use a mesh instead of CSG. Union and Negate with primitives will never get you exactly what you want for an organic model anyway, and CSG is notoriously bad with triangle count and normal mapping (this is why your lanturn looks like crumpled paper instead of a smooth aquatic animal). And of course you have to have a different CSG for every color you want to use and they don’t support UV mapping. Making a pokemon with CSG right now sounds kind of insane tbh.

5 Likes

While a mesh would undoubtedly be better, we want the models to take advantage of certain basepart properties. In the example of the Lanturn shown in my original post, all parts are Smooth Plastic except for the 2 orbs on its head, which are Neon. Some other models use the Reflectance property. To the best of my knowledge, it wouldn’t be possible to replicate this with textured meshes. Instead, we would have to keep all parts split up and singularly colored, while being texture-less. My game works in such a way that it doesn’t directly store a model for a “Shiny Lanturn”. Instead, it stores colors on the normal Lanturn and corresponding colors on a shiny Lanturn, and automatically converts them on run time. My game also has a variety of different skins that make it even more complex, such as the (extremely rare) rainbow skin shown below:

https://i.gyazo.com/1f09578be70c739ed745cab6860238dc.mp4

While not in the devforum at this time, @Disgustedorito messaged me on Roblox with the suggestion of exporting CSG parts to an external program (such as Blender), cleaning them up, and then importing them back. Would this be a viable solution? And if so, is there a simple way to do this in bulk (i.e. 1000+ unions) or would it all have to be done manually?

Thanks!

2 Likes

MeshParts and Unions should behave similarly. SpecialMeshes on the other hand don’t currently support materials and map decals differently.

Although exporting and reimporting CSG parts would probably work, I’ve found that you probably get the best results by making an entirely new mesh since you have better control over the individual faces and vertices.

4 Likes

I hate to throw this off topic, but it is a question that my building partner has pondered for some time: is it more or less efficient to combine several parts into one union? For example, if I create a door, is it more efficient to use a union instead of keeping the parts separate? Even if I am not using any union operation modifiers such as the negate feature? Basically just combining all of the parts into one entity?

1 Like

It is more efficient to use individual parts where you can. Roblox compresses property data for transmission, so sending over individual basic parts is very cheap. Besides, only the properties of each part have to be sent, not the mesh, since the client already knows how to draw a basic part.

If you have a CSG with 3 parts, then the client needs to download the vertex and normal data of that CSG part. It doesn’t recognise it as a union of 3 loose basic parts anymore. It also can’t render the CSG easily in batches together with basic parts anymore, since it is a special case.

So, creating a CSG out of the parts is both more expensive to render, and also requires more transmission space since it has to send the entire vertex and normal data of the mesh.

5 Likes

You only have to transmit the mesh once. So if you have a single door then it’s going to be significantly more expensive to be a union. But if you have 5000 doors then duplicating a union 5000 times is going to be much cheaper than duplicating 10 door parts 5000 times.

3 Likes