BodyPartDescription API Errors

Following the release of the Upgraded HumanoidDescription API changes which added the new BodyPartDescription, my game has started receiving errors for it.


image

Expected behavior

This upgraded API was announced to be “fully backwards compatible with the old HumanoidDescription APIs” so my game shouldn’t be affected by these changes.

5 Likes

Thanks for your bug report.

This happened because during the rollout of the new HumanoidDescription API, there was a circumstance when publishing from a team create game to another place caused duplicate AccessoryDescriptions or BodyPartDescriptions to be created. We have now enabled this feature for studio and this duplication should no longer be happening but it won’t fix games where it has already occurred. To fix games where it has already occurred, you can close and reopen studio to make sure you have the feature enabled and then run the following script:

local LOCATIONS_TO_PROCESS = {
	game:GetService("Workspace"),
	game:GetService("ReplicatedStorage"),
	game:GetService("ServerStorage"),
	game:GetService("ServerScriptService"),
	game:GetService("StarterGui"),
	game:GetService("ReplicatedFirst"),
	game:GetService("StarterPack"),
	game:GetService("StarterPlayer"),
	game:GetService("Lighting"),
}

local totalDuplicatesRemoved = 0

local function deduplicateSubDescriptions(humanoidDescription, className, getKeyFunction)
	local seenKeys = {}
	local childrenToRemove = {}

	for _, child in humanoidDescription:GetChildren() do
		if child:IsA(className) then
			local key = getKeyFunction(child)
			
			if seenKeys[key] then
				table.insert(childrenToRemove, child)
			else
				seenKeys[key] = true
			end
		end
	end

	for _, child in childrenToRemove do
		child:Destroy()
		totalDuplicatesRemoved = totalDuplicatesRemoved + 1
	end
end

local function processChildrenRecursive(instance)
	if instance:IsA("HumanoidDescription") then
		deduplicateSubDescriptions(instance, "AccessoryDescription", function(accessoryDescription)
			return accessoryDescription.AssetId
		end)
		deduplicateSubDescriptions(instance, "BodyPartDescription", function(bodyPartDescription)
			return bodyPartDescription.BodyPart
		end)
		return
	end

	for _, child in instance:GetChildren() do
		processChildrenRecursive(child)
	end
end

for _, location in LOCATIONS_TO_PROCESS do
	processChildrenRecursive(location)
end

print("Total duplicate AccessoryDescriptions and BodyPartDescriptions removed:", totalDuplicatesRemoved)

Sorry for the inconvenience caused.

2 Likes

Did this also affect games that haven’t been updated since?
Mine was last updated 4 days ago so a few days before these changes
image

1 Like

We actually started rolling this out for game and team create servers last week, before we published the devforum post.

1 Like

After running the code above, it seems to have a bug where it clears other BodyPartDescription’s that are required. This only occurred for the “Noob” character which doesn’t have any accessories. I think this is due to the default bodyparts for a character having an assetid of 0.


image
image

What it should look like:
image
image

1 Like

This is a good point, I have updated my script to deduplicate BodyPartDescriptions by BodyPart instead of by AssetId. I have edited my post above in case anyone else needs this.

1 Like

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