Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[BUG] Assigning Sprite Object to AssetReferenceSprite.editorAsset fails

Discussion in 'Addressables' started by CapnCromulent, Jan 4, 2019.

  1. CapnCromulent

    CapnCromulent

    Joined:
    Sep 7, 2010
    Posts:
    45
    I'm building an editor tool that automatically assigns AssetReferences within ScriptableObjects, and it looks like there's a bug when trying to do:
    Code (CSharp):
    1. data.spriteReference = new AssetRefereceSprite()
    2. data.spriteReference.editorAsset = AssetDatabase.LoadAssetAtPath<Sprite>(spritePath);
    In the property setter, it trips up on
    Code (CSharp):
    1. var type = AssetDatabase.GetMainAssetTypeAtPath(path);
    2. if (!ValidateType(type))
    3. {
    4.     Addressables.LogWarningFormat("Invalid type for AssetReference {0}, path = '{1}'.", type.FullName, path);
    5. }
    because the MainAssetTypeAtPath is Texture2D, and ValidateType fails. Is it intentional to use GetMainAssetTypeAtPath? Why not just get the type of the actual object?
     
  2. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    Good discovery. There are some changes to how AssetReferences restrict assignment coming in the next release. I'll try to slip in an improvement for this as well.
     
    MNNoxMortem likes this.