How can I serialize a union?

I need to save a union into datastorage, and then build it again. (union with an unknown amount of parts, unions, and intersections)

I don’t even know where to start?

I think order must matter here’s an example:


I don’t think there’s any other way to get this shape that has less steps than this

union needs its properties saved
union needs to be taken apart
union parts’ properties need to be saved

parts of the union need to be created
parts need to be given their properties
union needs to be created
union needs to be given its properties

Can someone expand this list precisely into every step? I can write the code myself, I just need to know what to write. Thanks!

Edit: Solid Modeling | Documentation - Roblox Creator Hub

Could you explain more about why you need a union into datastorage? Is serverstorage not allowed?

I want a player to create their own union, then save it, leave the game, join back the next day, and still have their union :D

I think that you can’t take apart unions using in-game scripts. This means that you will have to store/serialize the properties of the parts you want to create a union of, just before making the union. Then based on their properties recreate them, and recreate the union using UnionAsync in your in-game code.

Keep in mind when it comes to serialization you don’t have to store all the properties of those parts, you should start by asking yourself “how many properties do I actually need to correctly recreate the union?”

Ouch… well okay, I’ll have to rethink a lot of things then. I still want the player to create custom shapes though…

Say a player wants to make a bowl, they can use two spheres, a cylinder, and a block to make one. So I guess every time a union is created, MainPart and OtherParts need to be put in folders whos parent is the union?

So like this:

union >
  MainPartFolder >
    part
  OtherPartsFolder >
    part
    part
    part

Correct?

Oh, and all of these parts should have their collisions turned off and transparency set to 1. I’m apprehensive about doing this in the workspace, as it could cause a lot of lag, but I don’t know where else to do this, as I have hundreds of parts named the same thing, and it would be a mess moving everything around.

Thanks!

Depends on your implementation. All you need to do is implement a way to store the information of the parts prior unioning them, because the process isn’t reversible. That’s also useful in case you want to allow the players to edit the union afterwards.

Basically you don’t need to have the parts in the workspace 24/7, you just need to have their information, somewhere. The only scenario where you actually need them in the workspace is while the user is editing the union(not just viewing it). You don’t need to render parts in order to have their info. For example you can store the info as a serialized string, or have parts in server storage, etc.

1 Like

Exactly! I’ll think about how I could potentially do this. Thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.