menu_bookDocumentation
SkinnedModelRenderer: Bone Merge, Animation Parameters, Sequences, Attachments, and Animation Events
SkinnedModelRenderer: Bone Merge, Animation Parameters, and Attachments
SkinnedModelRenderer extends ModelRenderer for models with bones and animations. It integrates with the SceneAnimationSystem for threaded animation updates.Bone Merge
Bone merge allows one skinned model to follow the bones of another — used for clothing, accessories, and attachments:
CSHARP
// Make this renderer follow the bones of another
myClothingRenderer.BoneMergeTarget = playerBodyRenderer;When BoneMergeTarget is set, the child renderer's SceneModel calls MergeBones() on the parent's SceneModel each frame. The child's transform is set to match the parent's.
Animation Parameters
Set animation graph parameters via the Set method (generated from the animgraph):
CSHARP
var renderer = GetComponent<SkinnedModelRenderer>();
// Set float parameter
renderer.Set( "speed", 200f );
// Set bool parameter
renderer.Set( "b_grounded", true );
// Set int parameter
renderer.Set( "move_style", 1 );Sequences (Direct Playback)
For playing animations without an animation graph:
CSHARP
renderer.UseAnimGraph = false;
renderer.Sequence.Name = "idle";
renderer.Sequence.IsLooping = true;
renderer.PlaybackRate = 1.0f;Attachments
Get world-space transform of a model attachment point:
CSHARP
var muzzleTransform = renderer.GetAttachment( "muzzle" );
if ( muzzleTransform.HasValue )
{
var muzzlePos = muzzleTransform.Value.Position;
}Bone Objects (CreateBoneObjects)
When CreateBoneObjects = true, child GameObjects are created for each bone. These can be used for procedural bone control:
CSHARP
renderer.CreateBoneObjects = true;
// Find a bone GameObject
var headBone = GameObject.Children.FirstOrDefault( x => x.Name == "head" );Animation Events
CSHARP
// Subscribe to animation events via SceneModel
renderer.SceneModel.OnFootstepEvent = ( foot, transform ) => PlayFootstep( foot, transform );
renderer.SceneModel.OnSoundEvent = ( name, transform ) => Sound.Play( name, transform.Position );
renderer.SceneModel.OnGenericEvent = ( name ) => HandleEvent( name );PlayAnimationsInEditorScene
CSHARP
renderer.PlayAnimationsInEditorScene = true; // play animations in editor sceneBy default, animations only play in game scenes. Set this to true to preview animations in the editor.
Was this helpful?