docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Sample: Create and upload Unity Editor assets

    You can use the Asset Database Uploader sample in the Unity Editor to create and upload assets from your Unity Project into your Unity Cloud project. By creating them and uploading them, your assets will be available in the Unity Asset Manager.

    The sample use the management endpoints that requires a minimum role of:

    • Asset Management Contributor.
      OR
    • Organization Owner.

    Before you start

    Before you use the Asset Database Uploader sample, you must have the following:

    • Installed Assets package
    • Installed Identity package
    • A valid Unity ID Account
    • Access to your Unity Gaming Services account
    • Access to Asset Manager service
    • A Unity Project with the Asset Manager service enabled, see: Asset Manager documentation
    Note

    While the Assets package doesn't depend on the Identity service, it is used in the sample to control the authentication process.

    Install the sample

    To install the sample, follow these steps:

    1. In your Unity Project window, go to Package Manager > Unity Cloud Assets.

    2. Expand the Samples section.

    3. On the right of the Asset Database Uploader sample, select Import.

      Screenshot of the samples import section of the package manager window

      After the import process is complete, you can view your imported assets in the Assets/Samples/Unity Cloud Assets folder.

      Screenshot of the imported sample

    Run the sample

    To run the sample, follow these steps:

    1. Go to Assets/Samples/Unity Cloud Assets/<package-version>/Asset Database Uploader/Scenes/AssetDatabaseUploaderSample.unity and open the scene.
    2. Select the AssetDatabaseUploader game object in the Hierarchy window.
    3. In the inspector window, select the Fetch Organizations and Projects button.
      Screenshot of the fetch organizations and projects button
    4. Select the Organization where you want to upload your assets to.
      Screenshot of the organization dropdown selection
    5. Select the Project where you want to upload your assets to.
      Screenshot of the project dropdown selection
    6. Set the folder path that contains your assets to upload.
      Screenshot of the local assets path textfield
    7. If you want to check which asset is already known in your Unity Cloud project, select the Search Assets button.
      Screenshot of the search assets button
    8. To upload your assets, select the Create and Upload Assets button.
      Screenshot of the upload assets button
    Note

    The script is basic and doesn't handle asset defined by multiple files. Each file is seen as a new asset. Also, all the uploaded assets are set with draft status. The script doesn't provide a way to change the status of an asset.

    Screenshot of the Fetch Organizations and Projects button

    The sample provide two time out settings:

    • One for the main queries like Fetch and Search for example.

    • One for the upload process.

      Screenshot of the main queries timeout textfield

    To change the upload timeout, select the AssetDatabaseUploader game object in the Hierarchy window. In the Inspector window, change the Upload Time Out value.

    Screenshot of the upload query timeout textfield

    Main components

    This section describes the scripts that make up the main components of the Asset Database Uploader sample.

    AssetsEditor services script

    The AssetsEditorServices class initializes and disposes of dependencies required by IAssetRepository. You can use this class to manage the Unity Cloud services and dependencies you use in your scripts.

    To open the AssetsEditorServices script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetsEditorServices.cs file.

    Organization and Project selector script

    The OrgAndProjectSelector script shows you how to do the following:

    • Retrieve Organizations and Projects from the Assets service.
    • Select an Organization and Project from a list of Organizations and Projects.

    To open the OrgAndProjectSelector script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/OrgAndProjectSelector.cs file.

    Assets Uploader script

    The AssetsUploader script shows you how to do the following:

    • Create an asset in a Unity Cloud Project
    • Create a file and attach it to the created asset
    • Upload the file contents

    To open the AssetsUploader script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetsUploader.cs file.

    The AssetsUploader class has one required component called OrgAndProjectSelector.

    Asset Database Uploader sample script

    The AssetDatabaseUploaderSample shows you how to do the following:

    • Integrate everything together the AssetsEditorServices, the OrgAndProjectSelector and the AssetsUploader scripts
    • Use the AssetsEditorServices class to get your authentication token
    • Use the AssetsEditorServices class to initialize the IOrganizationRepository, IAssetRepository
    • Initialize the OrgAndProjectSelector script
    • Initialize the AssetsUploader script

    To open the Asset Database Uploader sample script, go to your Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/AssetDatabaseUploaderSample.cs file.

    Inspector UI scripts

    The sample includes a set of Editor UI scripts. To open the scripts, go to Assets/Samples/Unity Cloud Assets/<package-version>/AssetDatabaseUploader/Scripts/Editor.

    Limitations

    The sample has the following limitations:

    • If your asset already exists in your Unity Cloud Project, the sample will not update your asset nor upload the file content. It will just skip it. For now, the API endpoints don't support to get the upload URL of an asset if the file and the content has not been created and uploaded as the same time than the Asset's creation.

    • Allows you to create one asset per 'file', you can add rules of your own to combine asset based on 'naming convention, or anything else'. An example would be to combine all files that have the same letters before the first _ . The example of files below would create two assets.

    Marble014_8K_Roughness.png Marble014_8K_NormalGL.png Marble014_8K_NormalDX.png Marble014_8K_Displacement.png Marble014_8K_Color.png Marble014_PREVIEW.jpg Marble014_8K-PNG.usdc Rock030_PREVIEW.jpg Rock030_8K_Roughness.png Rock030_8K_NormalGL.png Rock030_8K_NormalDX.png Rock030_8K_Displacement.png Rock030_8K_Color.png Rock030_8K_AmbientOcclusion.png

    Go further with your sample

    This section describes other things you can do with the Asset Database Uploader sample.

    Step-by-step mode

    The sample provide a step by step mode to help you understand how the script works. If you want to follow each step instead of doing everything with one selection, enable the step by step mode.

    1. To enable the step by step mode, select the AssetDatabaseUploader game object in the Hierarchy window.
    2. In the inspector window, check the Step By Step checkbox.

    3. Screenshot of the step by step mode section
    4. Then like the Create and Upload Assets button, select each action button one by one following this order:
      1. Create Assets
      2. Create Asset Files
      3. Upload Created Assets

    Troubleshooting

    Refer to the troubleshooting section for help with sample issues.

    In This Article
    Back to top
    Copyright © 2024 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)