# ObjectReferenceKeyframe

> Keyframe to an Object reference.

## Definition

* **Type:** Struct
* **Namespace:** [UnityEditor](/engine/6000.5/script-reference/unityeditor.md)
* **Assembly:** UnityEditor.CoreModule

```csharp
public struct ObjectReferenceKeyframe
```

## Remarks

Use an object reference keyframe to create an array of [Object](/engine/6000.5/script-reference/unityengine/object.md) references. An [AnimationClip](/engine/6000.5/script-reference/unityengine/animationclip.md) uses an array of [Object](/engine/6000.5/script-reference/unityengine/object.md) references to animate properties.

Use the [AnimationUtility.SetObjectReferenceCurve](/engine/6000.5/script-reference/unityeditor/animationutility/setobjectreferencecurve.md) and [AnimationUtility.SetObjectReferenceCurves](/engine/6000.5/script-reference/unityeditor/animationutility/setobjectreferencecurves.md) methods to assign [ObjectReferenceKeyframe](/engine/6000.5/script-reference/unityeditor/objectreferencekeyframe.md) arrays of [Object](/engine/6000.5/script-reference/unityengine/object.md) reference properties to an [AnimationClip](/engine/6000.5/script-reference/unityengine/animationclip.md). Use the [AnimationUtility.GetObjectReferenceCurve](/engine/6000.5/script-reference/unityeditor/animationutility/getobjectreferencecurve.md) method to retrieve an [ObjectReferenceKeyframe](/engine/6000.5/script-reference/unityeditor/objectreferencekeyframe.md) array for an [Object](/engine/6000.5/script-reference/unityengine/object.md) reference property.

Additional Resources: [AnimationClip](/engine/6000.5/script-reference/unityengine/animationclip.md) [AnimationUtility.SetObjectReferenceCurve](/engine/6000.5/script-reference/unityeditor/animationutility/setobjectreferencecurve.md) [AnimationUtility.SetObjectReferenceCurves](/engine/6000.5/script-reference/unityeditor/animationutility/setobjectreferencecurves.md) [AnimationUtility.GetObjectReferenceCurve](/engine/6000.5/script-reference/unityeditor/animationutility/getobjectreferencecurve.md).

## Examples

```csharp
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                                                                                          |
| ------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |
| [time](/engine/6000.5/script-reference/unityeditor/objectreferencekeyframe/time.md)   | The time of the keyframe.                                                                            |
| [value](/engine/6000.5/script-reference/unityeditor/objectreferencekeyframe/value.md) | The [Object](/engine/6000.5/script-reference/unityengine/object.md) reference value of the keyframe. |
