docs.unity3d.com
    Show / Hide Table of Contents

    Class SequenceAssetUtility

    SequenceAssetUtility provides multiple functions to help creates and manipulates Sequence Asset Prefabs and Variants. A Sequence Asset is a Regular or a Variant Prefab "tagged" using the SequenceAsset component. Sequence Assets are visible and manageable in the Sequences window and are Prefabs ready to be used in a MasterSequence.

    Inheritance
    Object
    SequenceAssetUtility
    Namespace: UnityEditor.Sequences
    Syntax
    public static class SequenceAssetUtility : object

    Methods

    CreateSource(String, String, Boolean, Boolean)

    Creates a new Regular prefab with the SequenceAsset component on it.

    Declaration
    public static GameObject CreateSource(string name, string type = null, bool animate = true, bool instantiate = false)
    Parameters
    Type Name Description
    String name

    The name of the Prefab asset to create.

    String type

    The Collection type of the Sequence Asset that should be set on the SequenceAsset component. This is to categorize Sequence Assets.

    Boolean animate

    If true, a new TimelineAsset will be created and setup in the Prefab. The TimelineAsset itself is saved in the AssetDatabase next to the Prefab asset. Otherwise, the TimelineAsset can be manually created and setup later on if needed.

    Boolean instantiate

    If true, the created Prefab asset will be instantiated in the current active scene. Otherwise it is only created on disk.

    Returns
    Type Description
    GameObject

    The created Regular Prefab asset.

    CreateVariant(GameObject, Boolean)

    Creates a new Variant Prefab for the specified Source Prefab.

    Declaration
    public static GameObject CreateVariant(GameObject source, bool instantiate = false)
    Parameters
    Type Name Description
    GameObject source

    A Regular Prefab to use to create the new Variant. This Prefab must have the SequenceAsset component and it has to be a Regular Prefab. Model Prefab or Variant Prefab are not supported as potential Source Sequence Asset for a new Sequence Asset Variant.

    Boolean instantiate

    If true, the created Prefab asset will be instantiated in the current active scene. Otherwise it is only created on disk.

    Returns
    Type Description
    GameObject

    The created Variant Prefab asset.

    Remarks

    If the specified source Sequence Asset has a Timeline setup, a new TimelineAsset is created and saved for the Variant prefab as well. The created TimelineAsset is a copy of the source Sequence Asset TimelineAsset but it won't inherit the changes made on the source TimelineAsset later on.

    Exceptions
    Type Condition
    SequenceAssetException

    Thrown when the specified Source is not a valid Sequence Asset Source. It must be a Regular Prefab with the SequenceAsset component on it.

    DeleteSourceAsset(GameObject, Boolean)

    Deletes a Sequence Asset Source. If there is a TimelineAsset attached, it is deleted as well. The folder that contains the Sequence Asset Source is deleted as well if it is empty after deleting the Sequence Asset itself.

    Declaration
    public static bool DeleteSourceAsset(GameObject source, bool deleteVariants = true)
    Parameters
    Type Name Description
    GameObject source

    The Sequence Asset Source to delete.

    Boolean deleteVariants

    If true, also delete any Sequence Asset Variant of the provided Source (see DeleteVariantAsset(GameObject)). Otherwise, only the Source is deleted. In this last case, the first Variant become a Regular Prefab and every other Variant have the first Variant as their Source.

    Returns
    Type Description
    Boolean

    True is the Sequence Asset Source and any Variants are correctly deleted.

    Exceptions
    Type Condition
    SequenceAssetException

    Thrown when the specified Source is not a valid Sequence Asset Source. It must be a Regular Prefab with the SequenceAsset component on it.

    DeleteVariantAsset(GameObject)

    Deletes a provided Sequence Asset Variant. If there is a TimelineAsset attached, it is deleted as well.

    Declaration
    public static bool DeleteVariantAsset(GameObject variant)
    Parameters
    Type Name Description
    GameObject variant

    The Sequence Asset Variant to delete.

    Returns
    Type Description
    Boolean

    True if the Sequence Asset Variant is correctly deleted.

    DuplicateVariant(GameObject)

    Duplicates a Sequence Asset Variant.

    Declaration
    public static GameObject DuplicateVariant(GameObject variant)
    Parameters
    Type Name Description
    GameObject variant

    The Sequence Asset Variant to duplicate.

    Returns
    Type Description
    GameObject

    The duplicated Sequence Asset Variant.

    Remarks

    If the Sequence Asset Variant to duplicate has a TimelineAsset setup, it is duplicated as well and setup on the duplicated Variant. Any Timeline bindings are correctly preserved.

    FindAllSources(String)

    Finds all the Sequence Asset Prefab Sources that exists in the Project.

    Declaration
    public static IEnumerable<GameObject> FindAllSources(string type = null)
    Parameters
    Type Name Description
    String type

    An optional Sequence Asset Collection type to limit the find on Sequence Assets.

    Returns
    Type Description
    IEnumerable<GameObject>

    A list of all the Sequence Asset Sources found.

    GetInstancesInSequence(PlayableDirector, String)

    Gets all Sequence Asset Prefab instances present in a Sequence. The list of instances is constructed by looking at the Sequence TimelineAsset and the children GameObjects of the Sequence GameObject.

    Declaration
    public static IEnumerable<GameObject> GetInstancesInSequence(PlayableDirector sequenceDirector, string type = null)
    Parameters
    Type Name Description
    PlayableDirector sequenceDirector

    The Sequence PlayableDirector to look for Sequence Asset instances.

    String type

    Optionally specify one Collection type to look for. Only Sequence Asset instances of this type are returned. Leave to null to return all instances.

    Returns
    Type Description
    IEnumerable<GameObject>

    A list of Sequence Asset Prefab instances.

    GetSource(GameObject)

    Gets the Sequence Asset Source of a specified Sequence Asset (Source or Variant).

    Declaration
    public static GameObject GetSource(GameObject prefab)
    Parameters
    Type Name Description
    GameObject prefab

    A Sequence Asset Prefab or Sequence Asset Prefab Variant to get the Source from.

    Returns
    Type Description
    GameObject

    The Sequence Asset Prefab Source of the specified Prefab. If the specified Prefab is already a Source, it is returned as is.

    Exceptions
    Type Condition
    SequenceAssetException

    Thrown when the specified Prefab is not a valid Sequence Asset. It must have the SequenceAsset component on it.

    GetType(GameObject)

    Gets the Collection type of a Sequence Asset Prefab.

    Declaration
    public static string GetType(GameObject prefab)
    Parameters
    Type Name Description
    GameObject prefab

    A Sequence Asset Prefab (Source or Variant) to get the Collection type from.

    Returns
    Type Description
    String

    The Collection type name of the Sequence Asset.

    Exceptions
    Type Condition
    SequenceAssetException

    Thrown when the specified Prefab is not a valid Sequence Asset. It must have the SequenceAsset component on it.

    GetVariants(GameObject)

    Gets the Sequence Asset Variants of a specified Sequence Asset Source.

    Declaration
    public static IEnumerable<GameObject> GetVariants(GameObject source)
    Parameters
    Type Name Description
    GameObject source

    The Sequence Asset Source to get the Variants from.

    Returns
    Type Description
    IEnumerable<GameObject>

    The list of Sequence Asset Variants of the specified Source.

    Exceptions
    Type Condition
    SequenceAssetException

    Thrown when the specified Source is not a valid Sequence Asset Source. It must be a Regular Prefab with the SequenceAsset component on it.

    HasVariants(GameObject)

    Checks if a specified Sequence Asset Prefab has Variants. Only Source Sequence Asset can possibly have Variants.

    Declaration
    public static bool HasVariants(GameObject source)
    Parameters
    Type Name Description
    GameObject source

    The Sequence Asset Prefab Source to search existing Variants from.

    Returns
    Type Description
    Boolean

    True if the specified Sequence Asset Prefab has Variants. Otherwise, false.

    InstantiateInSequence(GameObject, PlayableDirector, TimelineClip)

    Instantiates the provided Sequence Asset (Source or Variant) in a Sequence.

    Declaration
    public static GameObject InstantiateInSequence(GameObject prefab, PlayableDirector sequenceDirector, TimelineClip clip = null)
    Parameters
    Type Name Description
    GameObject prefab

    The Sequence Asset Prefab to instantiate (Source or Variant).

    PlayableDirector sequenceDirector

    The Sequence PlayableDirector in which to instantiate the Sequence Asset. The Sequence Asset Prefab is instantiated under PlayableDirector.gameObject. If the provided Sequence Asset has a TimelineAsset setup to it, then a new SequenceAssetTrack and a clip are created in the PlayableDirector.playableAsset (the Sequence TimelineAsset) and bind to the Sequence Asset Prefab instance.

    TimelineClip clip

    User can optionally provide an existing TimelineClip to bind the Sequence Asset Prefab instance to. The asset of this TimelineClip must be a SequenceAssetPlayableAsset.

    Returns
    Type Description
    GameObject

    The Sequence Asset Prefab instance.

    IsSequenceAsset(GameObject)

    Indicates if the specified Prefab a Sequence Asset or not.

    Declaration
    public static bool IsSequenceAsset(GameObject prefab)
    Parameters
    Type Name Description
    GameObject prefab

    A Prefab to check if it is a Sequence Asset. I.e. if it has the SequenceAsset component on it.

    Returns
    Type Description
    Boolean

    True if the specified Prefab is a Sequence Asset, false otherwise.

    IsSource(GameObject)

    Indicates if the specified Sequence Asset is a Source Prefab or not.

    Declaration
    public static bool IsSource(GameObject prefab)
    Parameters
    Type Name Description
    GameObject prefab

    The Sequence Asset Prefab to check if it is a Source.

    Returns
    Type Description
    Boolean

    True if the specified Sequence Asset is a Source, false otherwise.

    IsVariant(GameObject)

    Indicates if the specified Sequence Asset is a Variant Prefab or not.

    Declaration
    public static bool IsVariant(GameObject prefab)
    Parameters
    Type Name Description
    GameObject prefab

    The Sequence Asset Prefab to check if it is a Variant.

    Returns
    Type Description
    Boolean

    True if the specified Sequence Asset is Variant, false otherwise.

    RemoveFromSequence(GameObject, PlayableDirector)

    Removes a Sequence Asset Prefab instance (Source or Variant) from a Sequence. This is the opposite of the InstantiateInSequence(GameObject, PlayableDirector, TimelineClip) action.

    Declaration
    public static void RemoveFromSequence(GameObject instance, PlayableDirector sequenceDirector)
    Parameters
    Type Name Description
    GameObject instance

    The Sequence Asset Prefab instance to remove from the Scene.

    PlayableDirector sequenceDirector

    The Sequence PlayableDirector in which the Sequence Asset is currently instantiated.

    RemoveFromSequence(GameObject, PlayableDirector, InteractionMode)

    Removes a Sequence Asset Prefab instance (Source or Variant) from a Sequence. This is the opposite of the InstantiateInSequence(GameObject, PlayableDirector, TimelineClip) action.

    Declaration
    public static void RemoveFromSequence(GameObject instance, PlayableDirector sequenceDirector, InteractionMode interactionMode)
    Parameters
    Type Name Description
    GameObject instance

    The Sequence Asset Prefab instance to remove from the Scene.

    PlayableDirector sequenceDirector

    The Sequence PlayableDirector in which the Sequence Asset is currently instantiated.

    InteractionMode interactionMode

    Choose the mode of interaction, user or automated.

    Rename(GameObject, String, String, Boolean, Boolean)

    Renames a Sequence Asset Prefab (Source or Variant). Any related assets (TimelineAsset if any) and folders are also renamed.

    Declaration
    public static string Rename(GameObject prefab, string oldName, string newName, bool renameVariants = true, bool renameInstances = true)
    Parameters
    Type Name Description
    GameObject prefab

    The Sequence Asset Prefab (Source or Variant) to rename.

    String oldName

    The old name of the Sequence Asset Prefab.

    String newName

    The new name to use for the rename.

    Boolean renameVariants

    Set to true (default) to also rename the associated Variants. This is only used if the Sequence Asset Prefab renamed is a Source.

    Boolean renameInstances

    Set to true (default) to rename any instances of the Sequence Asset Prefab.

    Returns
    Type Description
    String

    The actual new name of the Sequence Asset Prefab. This function will ensure that the Sequence Asset Prefab is renamed with a unique name, so this returned value can be different from the newName. If it is, it is simply post-fixed with a unique number.

    UpdateInstanceInSequence(GameObject, GameObject, PlayableDirector, InteractionMode)

    Updates a Sequence Asset instance to another in a specified Sequence. This is used to switch a Sequence Asset Source for one of its Variant or switch a Sequence Asset Variant for another Variant of the same Sequence Asset source.

    Declaration
    public static GameObject UpdateInstanceInSequence(GameObject oldInstance, GameObject newPrefab, PlayableDirector sequenceDirector, InteractionMode interactionMode = null)
    Parameters
    Type Name Description
    GameObject oldInstance

    The old Sequence Asset Prefab to remove (see RemoveFromSequence(GameObject, PlayableDirector))

    GameObject newPrefab

    The new Sequence Asset Prefab to instantiate (see InstantiateInSequence(GameObject, PlayableDirector, TimelineClip))

    PlayableDirector sequenceDirector

    The Sequence PlayableDirector to update.

    InteractionMode interactionMode

    If the interactionMode is InteractionMode.UserAction, then the user is asked to validate the update if the removed Sequence Asset needs to be saved. If this is called in a script that can't ask for user validation, use InteractionMode.AutomatedAction and verify that no changes can be lost on the oldInstance prior calling this function.

    Returns
    Type Description
    GameObject

    The new Sequence Asset instance (i.e. the instance of newPrefab).

    Back to top
    Terms of use
    Copyright © 2023 Unity Technologies — Terms of use
    • Legal
    • Privacy Policy
    • Cookies
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)
    "Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
    Generated by DocFX on 18 October 2023