Skip to content

Instantly share code, notes, and snippets.

@jeremedia
Last active August 12, 2023 04:54
Show Gist options
  • Save jeremedia/9a29117a8b8efb86990d395b996083a3 to your computer and use it in GitHub Desktop.
Save jeremedia/9a29117a8b8efb86990d395b996083a3 to your computer and use it in GitHub Desktop.
// From:https://forum.unity.com/threads/set-asset-as-addressable-through-script.718751/#post-5718025
// Code to make Unity assets "addressable"
// Use this object to manipulate addressables
var settings = AddressableAssetSettingsDefaultObject.Settings;
// Create and Remove groups and labels and custom address:
string group_name = "YourGroupName";
string label_name = "YourLabelName";
string path_to_object = "Assets/path/to/your/object/";
string custom_address = "Custom address here";
//Create a group
settings.CreateGroup(group_name, false, false, false, new List<AddressableAssetGroupSchema> { settings.DefaultGroup.Schemas[0] });
//Create a Label
settings.AddLabel(label_name, false);
//Remove a group
AddressableAssetGroup g = settings.FindGroup(group_name);
settings.RemoveGroup(g);
//Remove a label
settings.RemoveLabel(label_name, false);
//Make a gameobject an addressable
AddressableAssetGroup g = settings.FindGroup(group_name);
var guid = AssetDatabase.AssetPathToGUID(path_to_object);
//This is the function that actually makes the object addressable
var entry = settings.CreateOrMoveEntry(guid, g);
entry.labels.Add(label_name);
entry.address = custom_address;
//You'll need these to run to save the changes!
settings.SetDirty(AddressableAssetSettings.ModificationEvent.EntryMoved, entry, true);
AssetDatabase.SaveAssets();
@Wolfos
Copy link

Wolfos commented Dec 24, 2022

So many helpful snippets here

@imjae
Copy link

imjae commented Aug 12, 2023

Good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment