Search Unity

Feedback Get Address at Runtime

Discussion in 'Addressables' started by Roycon, Jun 9, 2020.

  1. Roycon

    Roycon

    Joined:
    Jul 10, 2012
    Posts:
    50
    Hi Addressables Team

    I'm wanting to get a address for a some assets at runtime.
    Does this exist somewhere in the Addressables API? I can't find anything for this

    I'm trying to load Mesh's and Materials to serialize/deserialize a DOTS world
    DOTS SerializeUtility (https://docs.unity3d.com/Packages/c....Entities.Serialization.SerializeUtility.html) give us a list of UnityEngine.Objects and I need to get the address for those (if they are addressable)
    Idealy I would like Addressables.GetKeyFor(UnityEngine.Object)

    Is this in the roadmap?
     

    Attached Files:

  2. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    Code (CSharp):
    1. var path = AssetDatabase.GetAssetPath(obj);
    2. var guid = AssetDatabase.AssetPathToGUID(path);
    3. string address = UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings.FindAssetEntry(guid).address;
    You can get the address in the editor with this code. There is no way to get it in the build, nor would it even make sense to (why would you need an address to an object you already have?).
     
  3. Roycon

    Roycon

    Joined:
    Jul 10, 2012
    Posts:
    50
    I need it in a build as all DOTS gives me is a list of UnityEngine.Object (Mesh's and Material's) which I need to save out somehow so I can reconstruct the exact same list again for loading later

    UnityEngine.Object already has a name field. I am currently using name + type to do my own lookup for a address but obviously that has issues (mainly duplicate file names will break it)

    Being able to get and save the address of something seems like a great saving/loading tool, even not in DOTS.
    In one of my older projects I had gameobjects/prefabs that had a script on it to get and store its address using the code above
    But to me this feels like something Addressables should give us rather then having to custom build
     
  4. ProtoTerminator

    ProtoTerminator

    Joined:
    Nov 19, 2013
    Posts:
    586
    That sounds like the right approach to me. What's wrong with it?

    Addressables is a system for retrieving assets. A save/load system is out of scope.