Skip to main content

UltimateRope

A class in Root.Township, the global namespace.

Third-party Ultimate Rope Editor component: builds a physics rope from jointed rigidbody links (procedural mesh, linked objects or imported bones), with optional coil and extension. Runs in edit mode too.

Constructors​

MemberWhat it is
UltimateRope()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

MemberWhat it is
bool AutoRegenerateEditor option to rebuild the rope when settings change.
UltimateRope.EAxis BoneAxisAxis along each imported bone, for ImportBones ropes.
float BoneColliderDiameterCollider diameter for imported bones.
float BoneColliderLengthCollider length as a fraction of each imported bone's length.
float BoneColliderOffsetCollider offset along the bone, as a fraction of the collider length.
int BoneColliderSkipCopied to each node's collider skip count, probably how many links to skip between colliders.
UltimateRope.EColliderType BoneColliderTypeCollider shape for imported bones. Default capsule.
GameObject BoneFirstFirst bone of an imported bone chain. Its name must end in digits.
GameObject BoneLastLast bone of an imported bone chain. Its name must end in digits.
string BoneListNamesNoCollidersComma list of bone numbers or ranges (like 1-3) that get no collider.
string BoneListNamesStaticComma list of bone numbers or ranges that stay static.
UltimateRope.EAxis CoilAxisRightCoil object axis the coil turns around. Default x.
UltimateRope.EAxis CoilAxisUpCoil object up axis. Default y.
float CoilDiameterDiameter of the coil's core.
int CoilNumBonesNumber of bones used to wrap rope around the coil. Default 50.
GameObject CoilObjectObject the rope winds around when HasACoil is on.
float CoilWidthWidth of the coil across its axis.
bool DeletedTrue when the rope has no generated links; setup methods skip deleted ropes.
bool EnablePrefabUsageRope editor option for saving the rope in a prefab. Not read by game code.
GameObject EventsObjectReceiverObject that gets OnBreakMethodName sent to it when a link breaks.
float ExtensibleLengthMaximum extra length an extensible rope can pay out.
bool HasACoilWhether an extensible procedural rope winds onto CoilObject.
UltimateRope.RopeBone[] ImportedBonesThe bone chain used by an ImportBones rope.
bool IsExtensibleWhether the rope can be extended at runtime with ExtendRope.
UltimateRope.EAxis LinkAxisAxis along the link mesh, for linked-object ropes. Default z.
float LinkJointAngularXLimitJoint swing limit in degrees around x. Zero locks it.
float LinkJointAngularYLimitJoint swing limit in degrees around y. Zero locks it.
float LinkJointAngularZLimitJoint twist limit in degrees around z. Zero locks it.
float LinkJointBreakForceForce at which link joints break (infinite by default).
float LinkJointBreakTorqueTorque at which link joints break (infinite by default).
float LinkJointDamperValueDamper of the joints' angular drive.
float LinkJointMaxForceValueMaximum force of the joints' angular drive.
float LinkJointSpringValueSpring strength of the joints' angular drive.
float[] LinkLengthsLength of each link in order, filled when the rope is built.
float LinkMassMass of each link rigidbody.
GameObject LinkObjectPrefab used for each link of a linked-objects rope.
float LinkOffsetObjectGap between linked objects, as a fraction of segment length.
int LinkSolverIterationCountPhysics solver iterations for each link rigidbody.
float LinkTwistAngleIncrementExtra twist in degrees added to each next link, for chain-like ropes.
float LinkTwistAngleStartTwist in degrees of the first link object.
bool LockStartEndInZAxisLocks each segment's end links to the node rotations instead of aiming them along the segment.
float[] m_afCoilBoneAnglesAngle of each coil bone around the coil.
float[] m_afCoilBoneRadiusesRadius of each coil bone from the coil centre.
float[] m_afCoilBoneXPosition of each coil bone across the coil's width.
bool m_bBonesAreImportedWhether the bone chain has been imported.
bool m_bLastStatusIsErrorWhether the last Regenerate failed. Read by IsLastStatusError.
bool m_bRopeStartInitialOrientationInitializedWhether the rope start's first position, rotation and scale have been saved.
float m_fCurrentCoilLengthLength of rope currently wound on the coil.
float m_fCurrentCoilRopeRadiusCurrent radius the rope winds at, used to turn coil rotation into length.
float m_fCurrentCoilTurnsLeftTurns of rope left on the coil.
float m_fCurrentExtensionHow far the rope is currently extended, between 0 and ExtensibleLength.
float m_fCurrentExtensionInputExtension value set from input, starts equal to m_fCurrentExtension.
int m_nFirstNonCoilNodeIndex of the first node that is not the coil: 1 with a coil, 0 without.
Quaternion m_qInitialRopeStartLocalRotSaved local rotation of the rope start.
string m_strAssetFileProbably the asset file the rope mesh was saved to by the editor.
string m_strStatusLast status message. Backing field for Status.
Vector3 m_v3InitialRopeStartLocalPosSaved local position of the rope start.
Vector3 m_v3InitialRopeStartLocalScaleSaved local scale of the rope start.
string OnBreakMethodNameMethod name sent to EventsObjectReceiver with break info when a link breaks.
bool PersistAfterPlayModeRope editor option to keep changes made in play mode. Not read by game code.
float RopeDiameterRope thickness (at least 0.01).
float RopeDiameterScaleXScales the procedural rope's width on x, for flat ropes. At least 0.01.
float RopeDiameterScaleYScales the procedural rope's width on y. At least 0.01.
int RopeLayerLayer the rope and its links use.
Material RopeMaterialMaterial for the procedural rope's surface.
List<UltimateRope.RopeNode> RopeNodesThe rope's segments, each ending at a node object.
PhysicMaterial RopePhysicsMaterialPhysic material put on link colliders.
Material RopeSectionMaterialMaterial for the procedural rope's end caps and broken ends.
int RopeSegmentSidesNumber of sides around the procedural rope. Default 8.
GameObject RopeStartObject the rope starts from.
float RopeTextureSectionTileMetersTexture tiling size for the end cap material.
float RopeTextureTileMetersMetres of rope per texture repeat along its length.
UltimateRope.ERopeType RopeTypeHow the rope is built: procedural mesh, linked objects or imported bones.
bool SendEventsWhether link breaks are sent to EventsObjectReceiver.
int TotalLinksNumber of links across all segments.
float TotalRopeLengthLength of all segments together.

Properties​

MemberWhat it is
string Status { get; set; }Message from the last build or change.

Methods​

MemberWhat it is
void AfterImportedBonesObjectRespawn()Puts imported bones back under the rope (or their non-bone parent if static) after the object respawns.
void BeforeImportedBonesObjectRespawn()Puts imported bones back under their original parents before the object respawns.
GameObject BuildStaticMeshObject(out string strStatusMessage)Bakes the rope into a static mesh object. Fails in editor play mode; returns a status message.
bool ChangeRopeDiameter(float fNewDiameter, float fNewScaleX, float fNewScaleY)Changes a procedural rope's diameter and scale and rebuilds its mesh. False for other rope types.
bool ChangeRopeSegmentSides(int nNewSegmentSides)Changes how many sides a procedural rope's cross-section has. False for other rope types.
void CheckNeedsStartExitLockZ()For procedural ropes, locks the first and last link of each segment to the node rotations when LockStartEndInZAxis is set.
void CreateNewNode(int nNode)Inserts an empty rope node after the given index.
void DeleteRope(bool bResetNodePositions = false, bool bDestroySkin = true)Removes the rope's links and joints, optionally resetting node transforms.
void DeleteRopeLinks()Destroys the generated link objects. Does nothing for imported bones.
void ExtendRope(UltimateRope.ERopeExtensionMode eRopeExtensionMode, float fIncrement)Extends or retracts an extensible rope, linearly or by turning the coil. Logs an error if not allowed.
void FillLinkMeshIndicesRope(int nLinearLinkIndex, int nTotalLinks, ref int[] indices, bool bBreakable, bool bBrokenLink = false)Writes the triangle indices for one link's rope surface. For broken links it leaves the gap open.
void FillLinkMeshIndicesSections(int nLinearLinkIndex, int nTotalLinks, ref int[] indices, bool bBreakable, bool bBrokenLink = false)Writes the triangle indices for the end caps of a link, or of the whole rope when not breakable.
bool FirstNodeIsCoil()Whether the first rope node is the coil.
bool HasDynamicSegmentNodes()True if any node object has a non-kinematic rigidbody.
bool IsLastStatusError()Whether the last build ended with an error in Status.
void MoveNodeDown(int nNode)Swaps a rope node with the next one.
void MoveNodeUp(int nNode)Swaps a rope node with the previous one.
void RecomputeCoil()Rebuilds the coil bones for the current coil length.
bool Regenerate(bool bResetNodePositions = false)Deletes and rebuilds the whole rope. Returns false and sets Status on bad settings.
void RemoveNode(int nNode)Removes a rope node.
void SetupRopeJoints()Creates the joints between links from the current settings.
void SetupRopeLinks()Sets up link colliders, rigidbodies and layer from the current settings.
void SetupRopeMaterials()Assigns the rope and section materials on a procedural rope's skinned renderer.
24 private and internal methods
MemberWhat it is
private void Awake()In play mode, makes the joints between links, sets up the links, and lays out the coil if the rope has one.
private bool BuildBoneHashString2GameObject(GameObject goRoot, GameObject goCurrent, ref Dictionary<string, GameObject> outHashString2GameObjects, ref string strErrorMessage)Maps every object name in a hierarchy to its object, failing if a name is used twice.
private bool BuildImportedBoneList(GameObject goBoneFirst, GameObject goBoneLast, List<int> ListImportBonesStatic, List<int> ListImportBonesNoCollider, out List<UltimateRope.RopeBone> outListImportedBones, out string strErrorMessage)Works out the bone name pattern from the first and last bone names and builds the imported bone list.
private bool BuildImportedBoneListTry(GameObject goRoot, string strPrefix, int nIndexFirst, int nIndexLast, int nDigitsFirst, int nDigitsLast, List<int> ListImportBonesStatic, List<int> ListImportBonesNoCollider, out List<UltimateRope.RopeBone> outListImportedBones, ref string strErrorMessage)Tries one name pattern and digit count to find each numbered bone, used by BuildImportedBoneList.
private void CheckAddCoilNode()For extensible procedural ropes with a coil, inserts a coil node at the start of RopeNodes.
private void CheckDelCoilNode()Removes the coil node from the start of RopeNodes if there is one.
private ConfigurableJoint CreateJoint(GameObject goObject, GameObject goConnectedTo, Vector3 v3Pivot)Adds a configurable joint to an object, connects it to another's rigidbody and sets its pivot.
private void CreateRopeJoints(bool bCheckIfBroken = false)Makes the joints between all links. When asked, skips joints that had broken.
private float ExtendRopeLinear(float fLinearIncrement)Moves links in or out of the rope end to extend or retract it, and returns the length actually changed.
private void FixedUpdate()Checks for broken joints, cuts the procedural mesh there, sends the break message, and stops the rest of that segment breaking.
private Vector3 GetAxisVector(UltimateRope.EAxis eAxis, float fLength)Returns a vector of the given length along an EAxis.
private int GetLinkAxisIndex()Returns 0, 1 or 2 for the axis links lie along (x, y or z).
private Vector3 GetLinkAxisOffset(float fValue)Returns an offset along the link axis for the rope type.
private bool GetLinkBoxColliderCenterAndSize(float fLinkLength, float fRopeDiameter, ref Vector3 v3CenterInOut, ref Vector3 v3SizeInOut)Works out a box collider's centre and size for one link.
private float GetLinkDiameter()Returns the rope's thickness: the procedural diameter, the link mesh's width, or the bone collider diameter.
private Quaternion GetLinkedObjectLocalRotation(float fTwistAngle = 0)Rotation that lines a link object up with LinkAxis, twisted by an angle.
private float GetLinkedObjectScale(float fSegmentLength, int nNumLinks)Scale for link objects so they fill a segment's length, allowing for LinkOffsetObject.
private void OnGUI()Empty.
private bool ParseBoneIndices(string strBoneList, out List<int> outListBoneIndices, out string strErrorMessage)Parses a comma list of bone numbers and ranges into a list of indices.
private void SetExtensibleLinkToKinematic(GameObject link, bool bKinematic)Makes a link kinematic (and unbreakable, collider off) while it is pulled in, or physical again when let out.
private void SetupCoilBones(float fCoilLength)Lays the coil node's bones around the coil for a given wound length.
private void SetupJoint(ConfigurableJoint joint)Applies the link joint limits, drive and break force settings to a configurable joint.
private void Start()Copies the current extension to the extension input.
private void Update()Empty.

Used in​

Members of other types that take, return or hold a UltimateRope: