Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


ObjectReferenceKeyframe

Keyframe to an Object reference.
Read time 1 minuteLast updated 4 days ago

Definition

  • Type: Struct
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule
public struct ObjectReferenceKeyframe

Remarks

Use an object reference keyframe to create an array of Object references. An AnimationClip uses an array of Object references to animate properties.
Use the AnimationUtility.SetObjectReferenceCurve and AnimationUtility.SetObjectReferenceCurves methods to assign ObjectReferenceKeyframe arrays of Object reference properties to an AnimationClip. Use the AnimationUtility.GetObjectReferenceCurve method to retrieve an ObjectReferenceKeyframe array for an Object reference property.

Examples

using UnityEditor;using UnityEngine;static class AnimationClipWithObjectReferenceKeyframesExample{ // This example creates an AnimationClip of a sequence of sprites selected // in the project view. The clip is saved as an asset in the project. [MenuItem("Example/Create Flip Book Animation Clip From Sprites")] static void CreateFlipBookAnimationClipFromSprites() { var selectedSprites = Selection.GetFiltered<Sprite>(SelectionMode.Unfiltered); if (selectedSprites == null || selectedSprites.Length == 0) { Debug.LogError("Please select sprites in the project view to create a clip for."); return; } AnimationClip clip = new AnimationClip(); var spriteCurve = new ObjectReferenceKeyframe[selectedSprites.Length]; for (int i = 0; i < selectedSprites.Length; ++i) { var sprite = selectedSprites[i]; spriteCurve[i] = new ObjectReferenceKeyframe { time = i/clip.frameRate, value = sprite }; } var spriteBinding = EditorCurveBinding.PPtrCurve("", typeof(SpriteRenderer), "m_Sprite"); AnimationUtility.SetObjectReferenceCurve(clip, spriteBinding, spriteCurve); AssetDatabase.CreateAsset(clip, AssetDatabase.GenerateUniqueAssetPath($"Assets/FlipBookClip.anim")); }}

Fields

Value

Description

timeThe time of the keyframe.
valueThe Object reference value of the keyframe.