Search Unity

Bug Duplicate asset in bundle - Unity > 2020.3.23

Discussion in 'Addressables' started by Twin-Stick, Jan 18, 2022.

  1. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    I have confirmed this duplicate assets issue only in versions > 2020.3.23 (2020.3.23 works fine).
    It doesn't seem to matter what version of addressables is being used.

    ISSUE
    Loading a group of assets via a label will result in duplicate assets being loaded. I have tested this in 2020.3.25 and 2020.3.26 (2020.3.23 works fine).
    NOTE: This is only a problem if the asset bundles are built in those versions of unity. For example, if I build the bundles in 2020.3.23, then open the project in 2020.3.26 - it behaves as expected. The issue seems to be with the building of the bundles.
    • 2020.3.23
      upload_2022-1-18_14-25-49.png
    • > 2020.3.23
      upload_2022-1-18_14-26-17.png
    CAUSE
    My guess is that for whatever reason, the build script is adding the asset in twice because it both is added into the bundle manually so it can be assigned a label, AND it is in a folder which is also in the bundle.
    It seems in 2020.3.23 it either checked if it already existed and skipped the asset. See screenshot below which shows the assets and directory structure (since you can't assign a label to a subfile of a folder - PS: it would be nice to be able to do this!)
    upload_2022-1-18_14-32-15.png
     
    phobos2077 likes this.
  2. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
  3. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    Hey there - interesting regarding the scriptable objects, because those are the assets which have been marked with a label in my screenshot above. I think you are correct that this is happening to scriptable objects - perhaps my theory about being nested in a folder which is also in the bundle is just happenstance.
    It's quite strange that it is only during the build process of the bundles.

    I'm not using Odin, so I don't think that is part of the problem. I'll post up the scriptable object's code...
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3. using UnityEngine.AddressableAssets;
    4. using System.Threading.Tasks;
    5. using DG.Tweening;
    6.  
    7. namespace Costumes
    8. {
    9.     [CreateAssetMenu(menuName ="Twin-Stick/Costume")]
    10.     public class CostumeData : ScriptableObject
    11.     {
    12.         public int costumeID;
    13.         public string costumeName;
    14.         public Sprite iconEnabled, iconDisabled;
    15.         [SerializeField] AssetReferenceGameObject costumeRef;
    16.         [SerializeField, TextArea] string unlockMessage;
    17.         public bool isLocked;
    18.         public bool hideEyes;
    19.      
    20.         public async Task<GameObject> LoadCostumeAsync()
    21.         {
    22.             if (costumeID == 0)
    23.                 return null;
    24.  
    25.             var op = Addressables.InstantiateAsync(costumeRef);
    26.             await op.Task;
    27.             return op.Result;
    28.         }
    29.  
    30.         public async void UnlockAsync()
    31.         {
    32.             GameState state = GameManager.Instance.CurrentState;
    33.             GameManager.Instance.CurrentState = GameState.None;
    34.             GameManager.Instance.Player.unlockCam.Priority = 200;
    35.             await DOVirtual.Float(1, 0.2f, .4f, (t) => Time.timeScale = t).AsyncWaitForCompletion();          
    36.  
    37.             CostumeManager.Instance.ChangeCostume(costumeID);
    38.  
    39.             await Task.Delay(2000);
    40.             DOVirtual.Float(.2f, 1f, 0.5f, (t) => Time.timeScale = t);
    41.  
    42.             // show UI message
    43.             await UIMessage.Instance.ShowAsync("New Costume!", unlockMessage);
    44.          
    45.             GameManager.Instance.Player.unlockCam.Priority = 0;
    46.  
    47.             // unlock data
    48.             isLocked = false;
    49.          
    50.             // save data
    51.             SettingsController.Instance.UnlockCostume(costumeID);
    52.  
    53.             GameManager.Instance.CurrentState = state;
    54.         }
    55.     }
    56.  
    57.     [CreateAssetMenu(menuName =("Twin-Stick/Skin"))]
    58.     public class SkinData : ScriptableObject
    59.     {
    60.         public int skinID;
    61.         public string skinName;
    62.         public string authorName;
    63.         public Material material;
    64.         public Sprite icon;
    65.     }
    66. }
    Do you have an asset references inside your SO's which are having this issue? Perhaps that is the link?
     
  4. phobos2077

    phobos2077

    Joined:
    Feb 10, 2018
    Posts:
    350
    Not in my case. I created minimal repro with only 1 string field. Inheriting from Odin class triggers this issue. I thought that ISerializationCallbackReceiver is the key, but seeing that you don't use it in your class, seems that the cause for this bug is more somehow involved. Hopefully my report will be acted upon.

    I suggest you to try and make a minimum repro for your case as well and issue a separate report, this will double the chances of this to get fixed.
     
    Twin-Stick likes this.
  5. Twin-Stick

    Twin-Stick

    Joined:
    Mar 9, 2016
    Posts:
    111
    Yes, 100% - it's such a strange bug!
    I'll be submitting my bug report and will link yours too.
     
    phobos2077 likes this.