AssemblyMass returns only the mass of the part, not the entire assembly

Problem

I’m making some objects that are composed of different parts which are welded together. I need the mass of the combined assembly to work with VectorForce. I have tried all three options, and I cannot get the total mass of the assembly, just the mass of the object itself.

The three options that I have tried (that I’m aware of) are as follows:

  • Part:GetMass()
  • Part.Mass
  • Part.AssemblyMass

All three return the same value which is incorrect. I’m beginning to think this is some kind of weird bug, I can work around it by summing the masses of all the parts, but isn’t that what Part.AssemblyMass is for?

Is anyone else having this problem?

Group the assembly into a model, then loop through all the parts, get their mass, and add it to a big value

local function CalculateMass(model:Model)
local TotalMass = 0
for _,part in model:GetChildren() do -- you can also do GetDescendants if you want
TotalMass += part:GetMass()
end
return TotalMass
end

i didnt check this, tell me if it works for you

EDIT: it works for me, even though im not sure this is what you need, but this is what i understood from the question
here is what i did

local model = workspace:WaitForChild("Model")

local function CalculateMass(model:Model)
	local TotalMass = 0
	for _,part in model:GetChildren() do -- you can also do GetDescendants if you want
		TotalMass += part:GetMass()
	end
	return TotalMass
end

local mass = CalculateMass(model)

print(mass)

i have tried using part.AssemblyMass for your question, but i also had no luck

EDIT: i managed to get part.AssemblyMass working
image
In this assembly Part1 is the one with all the welds, where it is set as the Part0.

local assembly = script.Parent.Parent

local function CalculateMass(model:Model)
	local TotalMass = 0
	for _,part in model:GetChildren() do -- you can also do GetDescendants if you want
		TotalMass += part:GetMass()
	end
	return TotalMass
end

local mass1 = CalculateMass(assembly)

local mass2 = script.Parent.AssemblyMass

print("Mass1 is " .. tostring(mass1))
print("Mass2 is " .. tostring(mass2))

using this script gave the same results for both prints
image

The problem might’ve been the fact that you used Weld instead of WeldConstraint or Motor6D, but this is just what i guess happened

Do you have any Parts with the Massless Property set to true?

I just tried it with a clean base plate in preparation for a bug report, but BasePart.AssemblyMass is working there, and I was using Weld to do it. So something very weird is going on. Thanks, but I don’t need the code. It’s easy enough to make a function to do it.

local function getMass(object: Instance)
	-- Setup
	local accumulateMass = 0
	local list = object:GetDescendents()

	-- Process
	for _, item in ipairs(list) do
		if item:IsA("BasePart") or item:IsA("UnionOperation") or
			item:IsA("MeshPart") or item:IsA("IntersectOperation")
		then
			accumulateMass += item.Mass
		end
	end

	-- Return Results
	return accumulateMass
end

Yeah, I had to because the wrong mass was being used in the force calculations. So I set Model:PrimaryPart to have mass and all other parts in the assembly have massless set to true. It was the only way to get it to work correctly.

As far as I know that’s the best way to do it.
Since you only have the 1 Part with Mass the Model assembly will only have the total Mass of that one Part + a bunch of 0’s.

Interesting, thought welds didnt work with this, they werent mentioned in the doc reference for Assemblies

I used Moon Animator’s Easy Weld utility to weld the model.

Thats also what i wanted to do the first time i wanted to test the assembly mass, but instead did the newer weld constraints, the fact that it also works with normal welds is pretty helpful, i dont always like to work with the constraint version of it