All Classes Namespaces Functions Variables Enumerations Properties Pages
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Properties | List of all members
PuppetMaster Class Reference

The master of puppets. Enables character animation to be played physically in muscle space. More...

Inherits MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, MonoBehaviour, and MonoBehaviour.

Collaboration diagram for PuppetMaster:
Collaboration graph
[legend]

Public Types

enum  Mode
 Active mode means all muscles are active and the character is physically simulated. Kinematic mode sets rigidbody.isKinematic to true for all the muscles and simply updates their position/rotation to match the target's. Disabled mode disables the ragdoll. Switching modes is done by simply changing this value, blending in/out will be handled automatically by the PuppetMaster. More...
 
enum  UpdateMode
 Normal means Animator is in Normal or Unscaled Time or Animation has Animate Physics unchecked. AnimatePhysics is Legacy only, when the Animation component has Animate Physics checked. FixedUpdate means Animator is used and in Animate Physics mode. In this case PuppetMaster will take control of updating the Animator in FixedUpdate. More...
 

Public Member Functions

void Teleport (Vector3 position, Quaternion rotation, bool moveToTarget)
 Teleports the puppet to the specified position and rotation. The operation will not be processed immediatelly, but the next time PuppetMaster reads. More...
 
void SetInternalCollisionsManual (bool collide, bool useInternalCollisionIgnores)
 Used for manual override of internal collision ignores. More...
 
void SetAngularLimitsManual (bool limited)
 Used for manual override of angular limit ignores. More...
 
void OnPreSimulate (float deltaTime)
 To be called before Physics.Simulate() if Physics.autoSimulation is false and PuppetMaster component disabled. Note that this method also updates the Animator so that is forced to disabled. More...
 
void OnPostSimulate ()
 To be called after Physics.Simulate() if Physics.autoSimulation is false and PuppetMaster component disabled. More...
 
void FlagInternalCollisionsForUpdate ()
 Call this if you have made changes to muscle.props.internalCollisionIgnores at runtime. More...
 
bool AddPropMuscle (ConfigurableJoint addPropMuscleTo, Vector3 position, Quaternion rotation, Vector3 additionalPinOffset, Transform targetParent=null, PuppetMasterProp initiateWithProp=null)
 Adds a PropMuscle to the puppet at runtime. If Vector3.zero passed for additionalPinOffset, additional pin will not be added. More...
 
bool IsDisconnecting (int muscleIndex)
 Is the muscle scheduled for disconnecting? More...
 
bool IsReconnecting (int muscleIndex)
 Is the muscle scheduled for reconnecting More...
 
void DisconnectMuscleRecursive (int index, MuscleDisconnectMode disconnectMode=MuscleDisconnectMode.Sever, bool deactivate=false)
 Disconnects muscle from index. In Sever mode, the muscle and it's children will be disconnected in one piece (cutting limb off). In Explode mode the muscle and all it's children will be cut off. If Deactivate is true, the disconnected muscle GameObjects will be deactivated. More...
 
void ReconnectMuscleRecursive (int index)
 Reconnects all muscles starting from the specified index. More...
 
void AddMuscle (ConfigurableJoint joint, Transform target, Rigidbody connectTo, Transform targetParent, Muscle.Props muscleProps=null, bool forceTreeHierarchy=false, bool forceLayers=true)
 NB! Make sure to call this from FixedUpdate! Creates a new muscle for the specified "joint" and targets it to the "target". The joint will be connected to the specified "connectTo" Muscle. Note that the joint will be binded to it's current position and rotation relative to the "connectTo", so make sure the added object is positioned correctly when calling this. This method allocates memory, avoid using it each frame. More...
 
void Rebuild ()
 Complete rebuild of this puppet's muscle hierarchy to it's default state as it was at first initiation (required that none of the original components have been destroyed). More...
 
void RemoveMuscleRecursive (ConfigurableJoint joint, bool attachTarget, bool blockTargetAnimation=false, MuscleRemoveMode removeMode=MuscleRemoveMode.Sever)
 Removes the muscle with the specified joint and all muscles connected to it from PuppetMaster management. This will not destroy the body part/prop, but just release it from following the target. If you call RemoveMuscleRecursive on an upper arm muscle, the entire arm will be disconnected from the rest of the body. More...
 
void ReplaceMuscle (ConfigurableJoint oldJoint, ConfigurableJoint newJoint)
 NB! Make sure to call this from FixedUpdate! Replaces a muscle with a new one. This can be used to replace props, but in most cases it would be faster and more efficient to do it by maintaining the muscle (the Joint and the Rigidbody) and just replacing the colliders and the graphical model. This method allocates memory, avoid using it each frame. More...
 
void SetMuscles (Muscle[] newMuscles)
 NB! Make sure to call this from FixedUpdate! Completely replaces the muscle structure. Make sure the new muscle objects are positioned and rotated correctly relative to their targets. This method allocates memory, avoid using it each frame. More...
 
void DisableMuscleRecursive (ConfigurableJoint joint)
 Disables the muscle with the specified joint and all muscles connected to it. This is a faster and more efficient alternative to RemoveMuscleRecursive, as it will not require reinitiating the muscles. More...
 
void EnableMuscleRecursive (ConfigurableJoint joint)
 Re-enables a previously disabled muscle and the muscles connected to it. More...
 
void FlattenHierarchy ()
 Flattens the ragdoll hierarchy so that all muscles are parented to the PuppetMaster. More...
 
void TreeHierarchy ()
 Builds a hierarchy tree from the muscles. More...
 
void FixMusclePositions ()
 Moves all muscles to the positions of their targets. More...
 
void FixMusclePositionsAndRotations ()
 Moves all muscles to the positions and rotations of their targets. More...
 
bool HierarchyIsFlat ()
 Are all the muscles parented to the PuppetMaster Transform? More...
 
void SwitchToActiveMode ()
 Switches this PuppetMaster to PuppetMaster.Mode.Active. More...
 
void SwitchToKinematicMode ()
 Switches this PuppetMaster to PuppetMaster.Mode.Kinematic. More...
 
void SwitchToDisabledMode ()
 Switches this PuppetMaster to PuppetMaster.Mode.Disabled. More...
 
void DisableImmediately ()
 Disables the Puppet immediately without waiting for normal mode switching procedures. More...
 
void SetMuscleWeights (Muscle.Group group, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for all muscles in the specified group. More...
 
void SetMuscleWeights (Transform target, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
void SetMuscleWeights (HumanBodyBones humanBodyBone, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
void SetMuscleWeightsRecursive (Transform target, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle with the specified target and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeightsRecursive (int muscleIndex, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle of the specified muscle index and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeightsRecursive (HumanBodyBones humanBodyBone, float muscleWeight, float pinWeight=1f, float mappingWeight=1f, float muscleDamper=1f)
 Sets the muscle weights for the muscle that has the humanBodyBone target (works only with a Humanoid avatar) and all it's child muscles (when called on the upper arm, will set weights for the upper arm, forearm and hand of the same limb). More...
 
void SetMuscleWeights (int muscleIndex, float muscleWeight, float pinWeight, float mappingWeight, float muscleDamper)
 Sets the muscle weights for the muscle with the specified index. More...
 
Muscle GetMuscle (Transform target)
 Returns the muscle that has the specified target. More...
 
Muscle GetMuscle (Rigidbody rigidbody)
 Returns the muscle of the specified Rigidbody. More...
 
Muscle GetMuscle (ConfigurableJoint joint)
 Returns the muscle of the specified Joint. More...
 
bool ContainsJoint (ConfigurableJoint joint)
 Does the PuppetMaster have a muscle for the specified joint. More...
 
int GetMuscleIndex (HumanBodyBones humanBodyBone)
 Returns the index of the muscle that has the humanBodyBone target (works only with a Humanoid avatar). More...
 
int GetMuscleIndex (Transform target)
 Returns the index of the muscle that has the specified target. Returns -1 if not found. More...
 
int GetMuscleIndex (Rigidbody rigidbody)
 Returns the index of the muscle that has the specified Rigidbody. Returns -1 if not found. More...
 
int GetMuscleIndex (ConfigurableJoint joint)
 Returns the index of the muscle that has the specified Joint. Returns -1 if not found. More...
 
void SetUpTo (Transform setUpTo, int characterControllerLayer, int ragdollLayer)
 Sets the ragdoll up as a Puppet. Assigns the specified layers to the animated target and the ragdoll. If setUpTo is the same Transform as the PuppetMaster's, the character will be duplicated and the duplicate will be used as the animated target. More...
 
void Kill ()
 Kill the puppet with the specified StateSettings More...
 
void Kill (StateSettings stateSettings)
 Kill the puppet with the specified StateSettings More...
 
void Freeze ()
 Unfreeze the puppet with the specified StateSettings. More...
 
void Freeze (StateSettings stateSettings)
 Unfreeze the puppet with the specified StateSettings. More...
 
void Resurrect ()
 Resurrect this instance from the Dead or Frozen state (unless frozen permanently). More...
 
void SampleTargetMappedState ()
 The pose that the target will be fixed to if calling FixTargetToSampledState(). This should normally be used only by the Puppet Behaviours. More...
 
void FixTargetToSampledState (float weight)
 Blend the target to the pose that was sampled by the last SampleTargetMappedState call. This should normally be used only by the Puppet Behaviours. More...
 
void StoreTargetMappedState ()
 Stores the current pose of the target for sampling. This should normally be used only by the Puppet Behaviours. More...
 
bool IsValid (bool log)
 Determines whether this PuppetMaster instance is valid for initiation. More...
 

Static Public Member Functions

static PuppetMaster SetUp (Transform target, Transform ragdoll, int characterControllerLayer, int ragdollLayer)
 Sets up a Puppet from the specified ragdoll and target characters. More...
 
static PuppetMaster SetUp (Transform target, int characterControllerLayer, int ragdollLayer)
 Sets up a Puppet using a single ragdoll character. This will duplicate the ragdoll character, remove the ragdoll components from the original and use it as the animated target. More...
 
static void RemoveRagdollComponents (Transform target, int characterControllerLayer)
 Removes all the ragdoll components (except Cloth colliders), including compound colliders that are not used by Cloth. Components on the 'target' GameObject will not be touched for they are probably not ragdoll components, but required by a character controller. More...
 

Public Attributes

PuppetMasterHumanoidConfig humanoidConfig
 Humanoid Config allows you to easily share PuppetMaster properties, including individual muscle props between Humanoid puppets. More...
 
Transform targetRoot
 The root Transform of the animated target character. More...
 
State state
 Sets/sets the state of the puppet (Alive, Dead or Frozen) Frozen means the ragdoll will be deactivated once it comes to stop in dead state.. More...
 
StateSettings stateSettings = StateSettings.Default
 Settings for killing and freezing the puppet.. More...
 
Mode mode
 Active mode means all muscles are active and the character is physically simulated. Kinematic mode sets rigidbody.isKinematic to true for all the muscles and simply updates their position/rotation to match the target's. Disabled mode disables the ragdoll. Switching modes is done by simply changing this value, blending in/out will be handled automatically by the PuppetMaster. More...
 
float blendTime = 0.1f
 The time of blending when switching from Active to Kinematic/Disabled or from Kinematic/Disabled to Active. Switching from Kinematic to Disabled or vice versa will be done instantly. More...
 
bool fixTargetTransforms = true
 If true, will fix the target character's Transforms to their default local positions and rotations in each update cycle to avoid drifting from additive reading-writing. Use this only if the target contains unanimated bones. More...
 
int solverIterationCount = 6
 Rigidbody.solverIterationCount for the muscles of this Puppet. More...
 
bool visualizeTargetPose = true
 If true, will draw the target's pose as green lines in the Scene view. This runs in the Editor only. If you wish to profile PuppetMaster, switch this off. More...
 
float mappingWeight = 1f
 The weight of mapping the animated character to the ragdoll pose. More...
 
float pinWeight = 1f
 The weight of pinning the muscles to the position of their animated targets using simple AddForce. More...
 
float muscleWeight = 1f
 The normalized strength of the muscles. Useful for blending muscle strength in/out when you have multiple puppets with various Muscle Spring values. More...
 
float muscleSpring = 100f
 The general strength of the muscles. PositionSpring of the ConfigurableJoints' Slerp Drive. More...
 
float muscleDamper = 0f
 The positionDamper of the ConfigurableJoints' Slerp Drive. More...
 
float pinPow = 4f
 Adjusts the slope of the pinWeight curve. Has effect only while interpolating pinWeight from 0 to 1 and back. More...
 
float pinDistanceFalloff = 5
 Reduces pinning force the farther away the target is. Bigger value loosens the pinning, resulting in sloppier behaviour. More...
 
bool angularPinning
 If disabled, only world space AddForce will be used to pin the ragdoll to the animation while 'Pin Weight' > 0. If enabled, AddTorque will also be used for rotational pinning. Keep it disabled if you don't see any noticeable improvement from it to avoid wasting CPU resources. More...
 
bool updateJointAnchors = true
 When the target has animated bones between the muscle bones, the joint anchors need to be updated in every update cycle because the muscles' targets move relative to each other in position space. This gives much more accurate results, but is computationally expensive so consider leaving it off. More...
 
bool supportTranslationAnimation
 Enable this if any of the target's bones has translation animation. More...
 
bool angularLimits
 Should the joints use angular limits? If the PuppetMaster fails to match the target's pose, it might be because the joint limits are too stiff and do not allow for such motion. Uncheck this to see if the limits are clamping the range of your puppet's animation. Since the joints are actuated, most PuppetMaster simulations will not actually require using joint limits at all. More...
 
bool internalCollisions
 Should the muscles collide with each other? Consider leaving this off while the puppet is pinned for performance and better accuracy. Since the joints are actuated, most PuppetMaster simulations will not actually require internal collisions at all. More...
 
Muscle[] muscles = new Muscle[0]
 The Muscles managed by this PuppetMaster. More...
 
PropMuscle[] propMuscles = new PropMuscle[0]
 All PropMuscles added to this PuppetMaster. More...
 
UpdateDelegate OnPostInitiate
 Called after the puppet has initiated. More...
 
UpdateDelegate OnRead
 Called before (and only if) reading. More...
 
UpdateDelegate OnWrite
 Called after (and only if) writing More...
 
UpdateDelegate OnPostLateUpdate
 Called after each LateUpdate. More...
 
UpdateDelegate OnFixTransforms
 Called when it's the right time to fix target transforms. More...
 
UpdateDelegate OnHierarchyChanged
 Called when the puppet hierarchy has changed by adding/removing muscles More...
 
MuscleDelegate OnMuscleRemoved
 Called when a muscle has been removed. More...
 
MuscleDelegate OnMuscleDisconnected
 Called when a muscle has been disconnected. More...
 
MuscleDelegate OnMuscleReconnected
 Called when muscles have been reconnected. More...
 
List< SolverManagersolvers = new List<SolverManager>()
 The list of solvers that will be updated by this PuppetMaster. When you add a Final-IK component in runtime after PuppetMaster has initiated, add it to this list using solver.Add(SolverManager solverManager). More...
 
bool manualInternalCollisionControl
 If true, PuppetMaster will not handle internal collision ignores and you can have full control over handling it (call SetInternalCollisionsManual();). More...
 
bool manualAngularLimitControl
 If true, PuppetMaster will not handle angular limits and you can have full control over handling it (call SetAngularLimitsManual();). More...
 
bool mapDisconnectedMuscles = true
 If disabled, disconnected bones will not be mapped to disconnected ragdoll parts. More...
 
bool storeTargetMappedState = true
 Store the mapped state of the target automatically? More...
 

Properties

Animator targetAnimator [get, set]
 Gets the Animator on the target. More...
 
Animation targetAnimation [get, set]
 Gets the Animation component on the target. More...
 
BehaviourBase[] behaviours [get, set]
 Array of all Puppet Behaviours More...
 
bool isActive [get]
 Returns true if the PuppetMaster is in active mode or blending in/out of it. More...
 
bool initiated [get, set]
 Has this PuppetMaster successfully initiated? More...
 
UpdateMode updateMode [get]
 Gets the current update mode. More...
 
bool controlsAnimator [get]
 If the Animator's update mode is "Animate Phyics", PuppetMaster will take control of updating the Animator (in FixedUpdate). This does not happen with Legacy. More...
 
bool isBlending [get]
 Is the PuppetMaster currently switching state or mode? More...
 
bool isSwitchingMode [get, set]
 Returns true if the PuppetMaster is in the middle of blending from a mode to mode. More...
 
bool isSwitchingState [get]
 Returns true if PuppetMaster is in the middle of switching states. Don't deactivate the PuppetMaster nor any of it's behaviours while it returns true. More...
 
bool isKilling [get, set]
 Is the puppet in the middle of a killing procedure (started by PuppetMaster.Kill())? More...
 
bool isAlive [get]
 Is the puppet alive or still dying? More...
 
bool isFrozen [get]
 Is the puppet frozen? More...
 

Detailed Description

The master of puppets. Enables character animation to be played physically in muscle space.