Unity’s new Addressable Assets are great, but I’m running into a bit of a headache. When hooking up to a prefab, instead of referencing a game object, I would typically reference specific script for managing it, such as EnemyController. Then When I dragged a prefab on to the field, it would only accept it if the prefab also contained an EnemyController behaviour on the root object.
However, I can’t figure out how to duplicate that behaviour with AssetReference. There doesn’t appear to be any generic type association for AssetReference to include it, and I have no idea how to extend it for this behaviour.
Anyone else accomplished this?
This is something people have been asking for a bit, so I threw together a sample to show you. It’s not quite complete as it only handles the editor/assignment end of things. On the loading/instantiating side, you will still need to call GetComponent to grab what you need. I plan to make that automatic at some point, but figured you’d rather have this now than wait for it to be perfect. Be sure to keep an eye on our samples repo for when we update this demo, as well as adding new ones.
Samples repo: GitHub - Unity-Technologies/Addressables-Sample: Demo project using Addressables package
I’d recommend looking through the base level readme there as it discusses each sample (including this one). To jump right to this sample, you can go here: Addressables-Sample/Basic/ComponentReference at master · Unity-Technologies/Addressables-Sample · GitHub
Hope this helps. Again, keep an eye on that repo for updates. Or keep an eye on this forum thread for when we discuss the samples: https://forum.unity.com/threads/addressables-sample-repo.676033/
-Bill