Datastoring Complex Unions

Hello, I have ran into an issue with my game’s character saving system. Almost every single character or accessory in my game is made up of very complex unions, and I have just found out you cannot use datastoreservice to store instances.

Example:

I am aware there is a bypass to this using serialization, however I am stuck due to the severe complexity of the unions within my game.

I have researched serialization and have come across the method of separating the union and then serializing each part, but the thing is each union is made up of other complex unions.

So far I have come up with something along the lines of this (but I am still very confused):

local function SerializeModel(Model)
			for i = 1, #Model:GetChildren() do
				local Part = Model:GetChildren()[i]
				if Part:IsA("Part") or Part:IsA("MeshPart") then
					-- serialize
				elseif Part:IsA("Union") then
					-- separate union
					-- serialize non union parts
					-- group union/negativeparts (group 1)
						-- separate group 1
						-- serealize parts
						-- group union/negativeparts (group 2)	
						-- repeat until no unions -- (group 3,4, etc.)
					
					-- upon loading, reunion each serialized part in reverse group order (group 3 unioned, then group 2 is unioned, etc.)
				end
			end
		end

Apologies if this isn’t properly formatted or is asking for too much, this is my first forum post.

1 Like

You’re not taking the serialization process as far as it should be. There was never a need to store the outfit itself, or try to serialize its components. Save its name and find the outfit to re-apply when in-game. If the user can customize its color, then save that information too

1 Like

There is a character editing system that allows people to create their own characters.

The example shown is only a preset character, people can make their own with other accessories either from the character editor or from preset characters.

Example:

This character uses a mixture of accessories from preset characters and accessories u can apply from within the character editor. These accessories also have custom colors that the player applied.

Should I put a unique ID to each possible accessory within the game (wether its from a preset character or an accessory from the editor), and then store the color & material values of each part within the datastore?

as long as they can’t make their own unions there is no reason to store the instance itself. You should only store necessary information. In this case, key to the accessory, color, offset texture. Properties the user is able to modify. Your serialization should only store necessary information and as compressed as you can, as there is a limit to how much storage one datastore key can use.

3 Likes