[Open Source] Rule Based Unity Addressable Asset Importer

A simple rule based addressable asset importer. It marks assets as addressable, by applying to files having a path matching the rule pattern.

Features

  • Path pattern supports both wildcard (*, ?) and regex
  • Specify a static group or dynamic group.
  • Add or replace labels
  • Address replacement (raw path, simplified, regex based replacement)
  • Install as upm package

Feel free to modify it based on your demand.

13 Likes

I love it! thanks for sharing with everyone.

1 Like

Really appreciated! It’s a really nice approach. One thing I added after forking and modifying the project is a ruleset for assigning a custom group name, including path folders.

Given a path “Assets/Level Assets/Props/Wooden Barrel/Barrel01.prefab”

%PATH% returns “Assets/Level Assets/Props/Wooden Barrel/Barrel01.prefab”

%PATH%[0] returns “Assets”
%PATH%[1] returns “Level Assets”
%PATH%[-1] returns “Barrel01.prefab” (cyclic)
%PATH%[-2] returns “Wooden Barrel”

So “%PATH%[-2]” would create an Asset Group called “Wooden Barrel” containing all barrels inside it.
Beware that if by any reason, there is another folder also called Wooden Barrel elsewhere in the project, and the same kind of ruleset is applied, when that ruleset imports an asset, it will be sent to the same asset group.

Also, I added an option in the ruleset to create group if it doesn’t exist, and also to delete if there’s no asset in it.

Of course, if no variable is used, it behaves like what you have today.

1 Like

Awsome, would you mind create a PR? I will find a time to merge it, maybe slightly delayed due to the crunch time of another project.

2 Likes

Sure! No problem. Just have to make a backport to your original code due to structural changes on my version.

1 Like

@danilonishimura I’ve merged your PR with a few changes

  • Group creation default off.
  • Changed %PATH%[0] syntax to {PATH[0]} to keep consistent with regex replacement. Now it possible to use both {PATH[index]} and ${group} in groupName/addressReplacement.
1 Like

Version 0.2.1

Changes

  • Added address/group replacement. Working with regex rule to build the address/group based on information captured from the path.
  • Added path elements extraction for address/group replacement (i.e. ${PATH[0]})
  • Added option to automatically create groups if not exist, default False.
  • Added option to remove empty groups except the default group, default False.
  • Added option to define if labels from ruleset are added or replace the current ones.
  • Added save, documentation buttons.
  • Improved documentation.

Thanks @AlkisFortuneFish @danilonishimura for the contributions.

1 Like

Version 0.2.2

Changes

  • Fixed simplified behavior.
  • Added unit tests.

I’ve been following this repo while ago it’s really amazing. <3

@Favo-Yang Manually re-importing assets from many directories proved to be a bit tedious, so I made piece of code that triggers the Addressable import by selecting a folder and clicking “AddressablesImporter : Check sub folders”.
Will create a PR soon.

1 Like

Oh, cool, I had a hacky version of that I could not be bothered to tidy up and submit, cheers for doing it properly! :slight_smile:

1 Like

Version 0.3.0

Changes

  • Added context menu for faster asset import/update.
2 Likes

@Favo-Yang Love your importer - it’s a wonderful thing.

We currently include the contents of AddressableAssetsData in version control, and it occasionally gets out of sync.

Not really sure of the specific sequence, but I’d really like to generate the addressables fresh in a build script. Then, I’d exclude the whole lot from git, apart from AddressableImportSettings.

Do you have any experience doing this and/or any pointers?

@Colin_MacLeod thanks for using the library.

Your idea may be achieve-able, but you need understand the concept of group,schemas and templates well. So you can selective what commit to VCS and leave the dynamic part (group) to the importer. The importer has a group template feature may help.

However consider all the works but little benefit, I would probably write a commit hook to force me commit the AddressableAssetsData folder. Depends on why “it occasionally gets out of sync”, you may have a good reason to implement it.

Yeah, I’m really not sure what’s causing the issue, that’s true. Seems to happen when 2 people create assets that map to addressables.

Regarding version control, the only thing I seem to need to keep is the AddressableImportSettings instance. It seems I can regenerate everything from that, by importing the appropriate folders?

If you only need default group, then probably yes, you can import default addressable folders, and leave the rest to the importer.

If you need more or changed any settings, then you need commit other stuffs to VCS as well, but ignore Assets/AddressableAssetsData/AssetGroups/*. I never tried this approach, so it may have more issues.

Not sure I fully understand @Favo-Yang . I am using the Group template but I am not creating any addressables that aren’t matched by the AddressableImportSettings.

It seems, to create the script I really just need to know the command to create default addressables (the button that appears on the addressables groups tab when you first open it), and the command to start the import for a given folder.

The method is

AddressableAssetSettingsDefaultObject.Settings = AddressableAssetSettings.Create(AddressableAssetSettingsDefaultObject.kDefaultConfigFolder, AddressableAssetSettingsDefaultObject.kDefaultConfigAssetName, true, true);

You may soon meet two issues however,

  • what if you want to change some schemas or group settings, to share with others, you may want to keep related files to VCS.
  • what if you want to create dynamic groups using custom group template? you need put the template file to VCS, and template reference schemas… end up with lots related stuffs into VCS.

That’s why I said, you may want to only ignore Assets/AddressableAssetsData/AssetGroups/* from VCS. That’s the only thing can be dynamic recreated and maintained by the importer.

Really sorry, I think I am missing a key point here. Thank you so much for taking the time to clarify this with me.

To try to make it clearer, let me show you one of our examples. I am using the group template - one of our rules creates groups for each avatar prefab type, like this:
5241827--523310--upload_2019-12-3_11-57-12.png

But I know that if I delete everything out of the AddressableAssetDataFolder, recreate the addressables and then reimport, these groups are dynamically created for me, all based on the info run AddressableImportSettings. So I’m not seeing which bit would need me to keep the AssetGroups folder?

You’re not using custom group template, but the default one. In such case it’s fine.

5242100--523361--upload_2019-12-4_2-50-32.png

However, there’s lots stuff you can configure on a group, bascailly everything under the content packing & loading, which it is actually a schema. The importer can not maintain those for you.

5242100--523367--upload_2019-12-4_2-52-36.png

1 Like