Search Unity

Setting up built in assets for builds

Discussion in 'Addressables' started by galvanicauston, Mar 26, 2019.

  1. galvanicauston

    galvanicauston

    Joined:
    Aug 17, 2018
    Posts:
    6
    I've been able to use the new addressable assets to load sprite images in my game in the editor, but the assets are not being included in builds. I believe there is some setup step I'm missing, but I couldn't find anything about built in assets in the documentation. Here's my setup:

    I'm loading the sprite through the async call:


    Code (CSharp):
    1.  
    2.         void Update()
    3.         {
    4.             if (_previousExpression != expressionPath)
    5.             {
    6.                 IAsyncOperation<Sprite> operation = Addressables.LoadAsset<Sprite>(_previousExpression);
    7.                 operation.Completed += LoadAsset;
    8.             }
    9.         }
    10.  
    11.         private void LoadAsset(IAsyncOperation<Sprite> obj)
    12.         {
    13.             _expressionImage.sprite = obj.Result;
    14.         }
    15.  
    I've got my assets added to the Default Local Group:
    upload_2019-3-25_17-9-41.png

    I've checked the Include in Build toggle for the asset settings:
    upload_2019-3-25_17-10-23.png

    Is there something else I need to setup? I'm targeting WebGL but I also tried Windows. I disabled IL2CPP engine stripping but still had the issue. This is the error I'm getting on WebGL:


    loading expression UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 45) UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    NullReferenceException encountered in operation UnityEngine.ResourceManagement.AsyncOperations.ChainOperation`2[UnityEngine.Sprite,UnityEngine.AddressableAssets.ResourceLocators.IResourceLocator], result='', status='Failed', valid=True, location=Assets/art/expressions/dan/dan-okay.png.. UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    (Filename: ./Runtime/Export/Debug.bindings.h Line: 45) UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    NullReferenceException: Object reference not set to an instance of an object. UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    UnityLoader.js:4:9380
    (Filename: currently not available on il2cpp Line: -1)

    My WebGL build does include a StreaminAssets directory with the assets named in the catalog. But the error indicates it can't find it. Is there some last step I'm missing?
     
  2. galvanicauston

    galvanicauston

    Joined:
    Aug 17, 2018
    Posts:
    6
    Finally figured out what my issue was when I compared my setup to the example project here: https://github.com/Unity-Technologies/Addressables-Sample

    My issue was that the LocalBuildPath in my AddressableAssetSettings was incorrect. It needed to be changed to 'Assets/StreamingASsets/aa/[BuildTarget]' I'm not sure how it was changed but that solved the issue.

    I was able to test this in editor by setting my Play Mode Script in the addressables window to Packed Play Mode so it provided the same results in editor as it does in the build.
     
  3. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053
    You shouldn't used a hardcoded StreamingAssets path at all. Your build path should be `[UnityEngine.AddressableAssets.Addressables.BuildPath]/[BuildTarget]` for local assets. This was mentioned in the changelog, but is understandably missed with all the chaos. In the upcoming release, we've added code to check for this common situation and alert the user.