Custom attributes

Intermediate You can import custom attributes created in modeling tools such as Maya. animated attributes. Attributes that aren’t animated can’t be imported.

1. Import custom attributes

  • Import animations.
  • Asset View, select the animation asset.
  • Property Grid, select Import custom attributes. When the assets are built, Xenko imports the custom attributes from the FBX file.

    2. Control custom attributes with a script

    animation script. NodeName_AttributeName. For example, if you have the node myNode with the custom attribute myAttribute, use myNode_myAttribute.

    Example script

    ```csusing Xenko.Animations;using Xenko.Engine;using Xenko.Rendering;using Xenko.Audio;using Xenko.Rendering.Materials; namespace Sample{ public class HologramScript : SyncScript { public Material MyMaterial;
    1. private AnimationComponent animationComponent; private AnimationProcessor animationProcessor; public override void Start() { base.Start(); animationComponent = Entity.GetOrCreate<AnimationComponent>(); animationProcessor =
    ().FirstOrDefault(); }
    1. public override void Update() { if (animationProcessor == null || MyMaterial == null) return;
    // Animation result may be Null if animation hasn’t been played yet. var animResult = animationProcessor.GetAnimationClipResult(animationComponent); if (animResult == null) return; // Read the value of the animated custom attribute: float emmisiveIntensity; unsafe { fixed (byte* structures = animResult.Data) { foreach (var channel in animResult.Channels) { if (!channel.IsUserCustomProperty) continue;
    1. var structureData = (float*)(structures + channel.Offset); var factor = *structureData++; if (factor == 0.0f) continue; var value = *structureData; if (channel.PropertyName ==
    “myNode_myProperty”) emmisiveIntensity = value; } } } // Bind the material parameter: MyMaterial.Passes[0].Parameters.Set(MaterialKeys.EmissiveIntensity, emmisiveIntensity) } } }