Jump to content

Getting total weight of vehicle in the VAB/SPH


Recommended Posts

This is likely a stupid question, but I'm not sure where to start. This is more of a "force myself to learn" project as opposed to something actually useful. I'd like to, for now, get the total weight of an assembled vehicle while in the editor. I don't necessarily need a full-blown howto, but a starting point would be more than I have now.

Link to comment
Share on other sites

There's EditorLogic.startPod that always point to the root part, from there you can recursively walk the part's children and calculate the mass. There's also EditorLogic.fetch.getSortedShipList () that directly gives you a list of parts. You might have to deal with part symmetry as well.

Link to comment
Share on other sites

Does part.mass take into account the masslessness of physics-disabled parts? You might have to account for that manually.

no, you have to check for that manually. And make a special case for the small landing gear, since its physicless is implemented in a hacky way and isn't set until the flight starts.

Link to comment
Share on other sites

Wow, thanks guys! I think I've got enough to get started now.

Basically for RealChute, I did it with a Part extension method and a sum.

//Part extension method, must be in a static class
public static float TotalMass(this Part part)
{
return part.physicalSignificance != Part.PhysicalSignificance.NONE ? part.mass + part.GetResourceMass() : 0f;
}

//Method to get vessel mass, anywhere else
public float VesselMass()
{
return EditorLogic.SortedShipList.Sum(p => p.TotalMass());
}

That does the job nicely and keeps it clean and prevent you from having to physiclsless check everytime you want to get mass.

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...