docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Use case: Update the status of assets

    Use the Unity Cloud Assets package to update the status of assets in the cloud.

    Note

    To update assets, you need the Asset Manager Admin role at the organization level or the Asset Manager Contributor add-on role at the project level. Asset Manager Contributors can manage assets only for the specific projects to which they have access.

    Before you start

    Before you start, do the following:

    1. Verify you have the required permissions. Read more about verifying permissions.

      Note

      Asset Manager roles define the permissions that you have for a single Asset Manager project. Depending on your work, permissions may vary across projects.

    2. Set up a Unity scene in the Unity Editor with an Organization and Project browser. Read more about setting up a Unity scene.

    3. Create assets in Unity Cloud any of the following ways:

      • Add assets using the Asset SDK.
      • Add a single asset or multiple assets through the dashboard.

    How do I...?

    View reachable statuses for an asset

    To view the next available statuses of an asset, follow these steps:

    1. Open the AssetManagementBehaviour script that you created as described in Get started with Asset SDK.
    2. Add the following code to the end of the class:
    
    public string[] ReachableStatuses { get; private set; }
    
    public async Task GetReachableStatuses()
    {
        ReachableStatuses = null;
        ReachableStatuses = await CurrentAsset.GetReachableStatusNamesAsync(default);
    }
    
    

    The code snippet sets a collection of the next available statuses for the asset.

    Update the status of an asset

    To update the status of an asset, follow these steps:

    1. Open the AssetManagementBehaviour script that you created as described in Get started with Asset SDK.
    2. Add the following code to the end of the class:
    
    public async Task UpdateStatusAsync(string reachableStatus)
    {
        await CurrentAsset.UpdateStatusAsync(reachableStatus, default);
        await GetReachableStatuses();
    }
    
    

    Add a UI for viewing and updating the status of assets

    To create a UI for updating the status of assets, follow these steps:

    1. In your Unity Project window, go to Assets > Scripts.
    2. Select and hold the Assets/Scripts folder.
    3. Go to Create > C# Script.
    4. Name your script UseCaseManageAssetStatusExample.
    5. Open the UseCaseManageAssetStatusExample script that you created in the previous step and replace the contents of the file with the following code sample:
    
    using System;
    using System.Collections.Generic;
    using System.Threading.Tasks;
    using Unity.Cloud.Assets;
    using Unity.Cloud.Common;
    using UnityEngine;
    
    public class UseCaseManageAssetStatusExampleUI : IAssetManagementUI
    {
        readonly AssetManagementBehaviour m_Behaviour;
    
        public UseCaseManageAssetStatusExampleUI(AssetManagementBehaviour behaviour)
        {
            m_Behaviour = behaviour;
        }
    
        public void OnGUI() { }
    }
    
    
    1. In the same script, replace the OnGUI function with the following code:
    
    IAsset m_CurrentAsset;
    
    public void OnGUI()
    {
        if (!m_Behaviour.IsProjectSelected) return;
    
        if (m_Behaviour.CurrentAsset == null)
        {
            GUILayout.Label(" ! No asset selected !");
            return;
        }
    
        if (m_CurrentAsset != m_Behaviour.CurrentAsset)
        {
            m_CurrentAsset = m_Behaviour.CurrentAsset;
            _ = m_Behaviour.GetReachableStatuses();
        }
    
        if (!m_Behaviour.AssetProperties.TryGetValue(m_CurrentAsset.Descriptor.AssetId, out var properties))
        {
            GUILayout.Label(" ! Asset properties not loaded !");
            return;
        }
    
        GUILayout.BeginVertical();
    
        GUILayout.Label($"Current Status: {properties.StatusName}");
    
        GUILayout.Space(5f);
    
        if (m_Behaviour.ReachableStatuses == null)
        {
            GUILayout.Label("Reachable Statuses: Loading...");
        }
        else
        {
            GUILayout.Label("Reachable Statuses:");
            foreach (var status in m_Behaviour.ReachableStatuses)
            {
                if (GUILayout.Button(status))
                {
                    _ = m_Behaviour.UpdateStatusAsync(status);
                }
            }
        }
    
        GUILayout.EndVertical();
    }
    
    
    1. Open the AssetManagementUI script that you created as described in Get started with Asset SDK and replace the contents of the Awake function with the following code:
    
    m_UI.Add(new OrganizationSelectionExampleUI(m_Behaviour));
    m_UI.Add(new ProjectSelectionExampleUI(m_Behaviour));
    m_UI.Add(new AssetSelectionExampleUI(m_Behaviour));
    m_UI.Add(new UseCaseManageAssetStatusExampleUI(m_Behaviour));
    
    

    The code snippet does the following:

    • Displays the current status of the asset.
    • Provides UI buttons to update the asset to the next available status.
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)