Search Unity

No addressable mark on Scriptable Objects

Discussion in 'Addressables' started by androshchuk-vladyslav, Aug 22, 2019.

  1. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    From newer version we don't have ability to check mark Addressable on ScriptableObjects. But that is really necessary. However if we mark parent folder as Addressable, ScriptableObject inside will be included.
     
  2. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Also will add request to exclude objects inside folder. For now I have something like this:
    Code (CSharp):
    1.     private void ExcludeObject(Object o, string excludedGroupName = "Excluded")
    2.     {
    3.         AddressableAssetSettings aaSettings = AddressableAssetSettingsDefaultObject.Settings;
    4.         AddressableAssetGroup group = aaSettings.FindGroup(excludedGroupName);
    5.         if (group == null)
    6.         {
    7.             group = aaSettings.CreateGroup(excludedGroupName, false, false, true, null);
    8.         }
    9.  
    10.         BundledAssetGroupSchema bundledAssetGroupSchema = group.GetSchema<BundledAssetGroupSchema>();
    11.         if (bundledAssetGroupSchema == null)
    12.         {
    13.             bundledAssetGroupSchema = group.AddSchema<BundledAssetGroupSchema>();
    14.         }
    15.         bundledAssetGroupSchema.IncludeInBuild = false;
    16.        
    17.         if (AssetDatabase.TryGetGUIDAndLocalFileIdentifier(o, out string settingsFileGuid, out long _))
    18.         {
    19.             aaSettings.CreateOrMoveEntry(settingsFileGuid, group);
    20.         }
    21.     }
     
    Last edited: Aug 22, 2019
  3. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    What version of Unity and Addressables is that with? As ScriptableObjects have an Addressable tick here. I don't personally tend to use that anyway, to be honest. Either I drag things directly into a group in the Addressables window, or I use @Favo-Yang's Rule-based Importer. You can create all sorts of funky rules, using RegEx to match what should be addressable and in what group based on its path, extract parts of the path to create the address, etc.
     
    Favo-Yang likes this.
  4. aurelien-morel-ubiant

    aurelien-morel-ubiant

    Joined:
    Sep 27, 2017
    Posts:
    275
    We use addressable on Scriptable Object too and it works. Don't hesitate to share your addressable package version and your unity's version too :)
     
  5. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Unity 2019.2f1. No tick out here:
    upload_2019-8-23_12-20-10.png
     
  6. TextusGames

    TextusGames

    Joined:
    Dec 8, 2016
    Posts:
    429
    2019.2.1 addressables 1.1.9

    On scriptable objects which are not parts of addressables the addressable checkbox or name filed is shown. In Scriptable objects that are the addressable system itselfs, there is no such checkbox.

    I guess it is intended.
     
    Last edited: Aug 23, 2019
  7. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    Why do you want to make an asset that references an Editor-only class addressable? You cannot make editor-side classes addressable.

    The relevant piece of code that makes the addressable tick not appear, in AssetInspectorGUI:

    Code (CSharp):
    1.  
    2. if (AddressableAssetUtility.GetPathAndGUIDFromTarget(t, out path, ref guid, out mainAssetType) &&
    3.     path.ToLower().Contains("assets") &&
    4.     mainAssetType != null &&
    5.     !BuildUtility.IsEditorAssembly(mainAssetType.Assembly))
    6.  
     
    unity_bill likes this.
  8. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Yes, but parent folder is marked as addressable. And this asset is included in build and spawn warnings about Editor Assembly only. I think this is a bug @unity_bill ? Need to be some method like CanBeAddressable() and check it when we recursively add by folder feature.

    And really need excludes)

    Thanks for providing a code! Don't seen that.
     
  9. unity_bill

    unity_bill

    Joined:
    Apr 11, 2017
    Posts:
    1,053

    When are the errors thrown? If it's during the build, then those errors are us saying "someone told us to build this, but we can't", which is fine. That just means we're warning you that we're excluding it from the build.

    If the errors are in the runtime, then we are including them (likely due to being confused by folders) and need to fix that.

    In either case, I'd definitely recommend restructuring your project such that you do not have editor assets in a folder marked as addressable (or folder in a folder in a folder...). Just seems like a good best practice to keep your editor assets separate from your "addressables should build these" assets.
     
  10. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    I need this asset in folder. It contains build-time and import settings for all assets inside this folder and needed only for runtime. It says that this folder should be imported in addressables in some way.

    Issue, on my opinion, is that marking folder as addressable include editor only assets (in this folder) in build.
     
  11. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    At the moment, the workflow for working with folders is rather primitive. You cannot do a lot of things that are crucial to the addressables workflow, such as changing the addresses of child items etc. Right now, the best tool to work with folders in Addressables is @Favo-Yang's importer. Give it a try, it will do everything you need and if you need any new features we can probably add them.
     
    unity_bill likes this.
  12. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    I seen it. But I have custom workflow and import pipeline) Maybe I should change from marking a folder to marking separate assets. But this way has disadvantages - tree view is bad and don't align by folder structure.
     
  13. AlkisFortuneFish

    AlkisFortuneFish

    Joined:
    Apr 26, 2013
    Posts:
    973
    So do I, I even have custom bundle packing modes in my version of the addressables system, I still migrated to the importer, after making some modifications to it (which are now part of the asset itself). I would say that right now, until the folder workflow improves, the folder structure is the only advantage you get by marking folders as addressable, everything else is a disadvantage.
     
    androshchuk-vladyslav likes this.
  14. androshchuk-vladyslav

    androshchuk-vladyslav

    Joined:
    Dec 13, 2015
    Posts:
    127
    Yes, you are right. I migrated to manually marking assets on import and it is muuuch better:
    Code (CSharp):
    1.         private static void ProcessAssetsInFolder(string folderPath, AddressableFeatureSettings fSettings, AddressableAssetSettings aaSettings)
    2.         {
    3.             string[] assets = AssetDatabase.FindAssets("", new[] {folderPath});
    4.  
    5.             foreach (string asset in assets)
    6.             {
    7.                 string assetPath = AssetDatabase.GUIDToAssetPath(asset);
    8.                 Type mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
    9.  
    10.                 if (BuildUtility.IsEditorAssembly(mainAssetType.Assembly) || AssetDatabase.IsValidFolder(assetPath))
    11.                 {
    12.                     aaSettings.RemoveAssetEntry(asset);
    13.                     continue;
    14.                 }
    15.              
    16.                 string assetAddress = assetPath.Replace(folderPath, fSettings.FeatureName);
    17.                 AddressableAssetEntry entry = aaSettings.CreateOrMoveEntry(asset, fSettings.ConnectedGroup, true);
    18.                 entry.SetAddress(assetAddress);
    19.             }
    20.         }
    P.S. This code triggers when AddressableFeatureSettings ScriptableObject is imported.
     
    AlkisFortuneFish likes this.