Use case: Start a transformation on a dataset
Use the Unity Cloud Assets package to perform the following:
- Start transformations on a given dataset.
- Fetch any previously started transformations.
Note
To manage 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:
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.
Set up a Unity scene in the Unity Editor with an Organization and Project browser. Read more about setting up a Unity scene.
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...?
Start a transformation
To start a transformation on a dataset, follow these steps:
- Open the
AssetManagementBehaviourscript that you created as described in Get started with Asset SDK. - Add the following code to the end of the class:
public async Task StartTransformationOnDataset(IDataset dataset, WorkflowType workflowType)
{
try
{
var creation = new TransformationCreation
{
WorkflowType = workflowType
};
var transformationDescriptor = await dataset.StartTransformationLiteAsync(creation, CancellationToken.None);
Debug.Log($"Transformation started: {transformationDescriptor.TransformationId}");
}
catch (Exception e)
{
Debug.LogError($"Failed to start transformation. {e}");
throw;
}
}
public async Task StartCustomTransformationOnDataset(IDataset dataset, string workflowName)
{
try
{
var creation = new TransformationCreation
{
WorkflowType = WorkflowType.Custom,
CustomWorkflowName = workflowName
};
var transformationDescriptor = await dataset.StartTransformationLiteAsync(creation, CancellationToken.None);
Debug.Log($"Transformation started: {transformationDescriptor.TransformationId}");
}
catch (Exception e)
{
Debug.LogError($"Failed to start transformation. {e}");
throw;
}
}
The code snippet starts a transformation on a selected dataset.
Get a transformation
To get a transformation that has been previously started on a dataset, regardless of its completion status, follow these steps:
- Open the
AssetManagementBehaviourscript that you created as described in Get started with Asset SDK. - Add the following code to the end of the class:
public async Task StartTransformationOnDataset(IDataset dataset, TransformationId transformationId)
{
try
{
var transformation = await dataset.GetTransformationAsync(transformationId, CancellationToken.None);
var transformationProperties = await transformation.GetPropertiesAsync(CancellationToken.None);
Debug.Log($"Transformation {transformation.Descriptor.TransformationId} current status is {transformationProperties.Status}");
}
catch (Exception e)
{
Debug.LogError($"Failed to get transformation. {e}");
throw;
}
}
The code snippet gets a transformation that was previously started on the dataset.