Search Unity

[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:
    43
    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

    Unity Technologies

    Joined:
    Apr 11, 2017
    Posts:
    581
    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.