Click or drag to resize

ILinkSourceBreakCurrentLink Method

Breaks the link between the source and the target.

Namespace:  KASAPIv2
Assembly:  KAS-API-v2 (in KAS-API-v2.dll) Version: KAS API v2
Syntax
C#
void BreakCurrentLink(
	LinkActorType actorType
)
Request Example View Source

Parameters

actorType
Type: KASAPIv2LinkActorType
Specifies what initiates the action. The final result of the action doesn't depend on it, but the visual and sound representations may differ for the different actors.
Remarks
It must not be called from the physics update methods (e.g. FixedUpdate or OnJointBreak) since the link's physical objects may be deleted immediately. If the link needs to be broken from these methods, use a coroutine to postpone the call till the end of the frame.
Examples
// Disconnects the source part from its target. Only once source can be connected on the part.
// And it can be connected to the exactly one target.
public static void DisconnectParts(Part srcPart) {
  var source = srcPart.FindModulesImplementing<ILinkSource>()
      .FirstOrDefault(s => s.linkTarget != null);
  if (source == null) {
    Debug.LogWarningFormat("Part is not connected to anything");
    return;
  }
  // LinkActorType.API tells the implementation to not execute any user facing effects on the
  // link. See LinkActorType for more details.
  source.BreakCurrentLink(LinkActorType.API);
}
Examples
public class ILinkSourceExample_BreakFromPhysyicalMethod : MonoBehaviour {
  public ILinkSource linkSource;

  // This method is called by Unity core during the physics update.
  IEnumerable OnJointBreak(float force) {
    Debug.LogWarningFormat("Link is broken with force: {0}", force);
    // Don't break the link from the physics methods! 
    yield return new WaitForEndOfFrame();
    // Now it's safe to change the physical objects.
    if (linkSource != null && linkSource.linkTarget != null) {
      linkSource.BreakCurrentLink(LinkActorType.Physics);
    }
  }
}
See Also