docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method ValidateAsset

    ValidateAsset(string)

    Checks whether the asset located at a path is valid for this asset reference. An asset is valid if it is of the correct type or if one of its sub-assets are.

    Declaration
    public override bool ValidateAsset(string path)
    Parameters
    Type Name Description
    string path

    The file path to the asset in question.

    Returns
    Type Description
    bool

    Whether the referenced asset is valid.

    Overrides
    AssetReferenceT<Sprite>.ValidateAsset(string)
    Remarks

    The asset can be either a SpriteAtlas or a Sprite.

    Examples

    The example below uses ValidateAsset to check if an asset at a specific path can be set.

    public bool IsPathValid()
    {
        string guid = AssetDatabase.AssetPathToGUID("Assets/Sprites/oldSprite.png");
        AssetReferenceSprite assetRef = new AssetReferenceSprite(guid);
    
    return assetRef.ValidateAsset("Assets/Sprites/newSprite.png");
    

    }

    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)