Last active
August 12, 2023 04:54
-
-
Save jeremedia/9a29117a8b8efb86990d395b996083a3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
So many helpful snippets here