Hello, I’m looking forward to using Addressables but I’m having a difficult time understanding how I’m to create a custom inspector for what I need. See the screenshot below for my current setup.
Things to note:
This is an inspector for a ScriptableObject
The labels are derived from an external data source of equipment, to which I want to associate arbitrary prefabs.
The labels are display names, not actual key values associated with equipment data, and they can change. They are not ideal for hard-coding into the Address field, and neither are the unique IDs since they are not intended to be human friendly.
The search field simply filters the display by label (eg: don’t draw the EditorGUILayout.ObjectField if the label doesn’t contain the string in the search field)
What I would want instead, is something like the above except with a way to call EditorGUILayout.AddressReferenceField or something like that, so that I can have an AddressReference for each equipment item. However, I don’t see how I’m to add such a field. How can accomplish this?
The AssetReference already uses a custom property drawer. I’m sure it’s possible to make that work in your system, but may require massaging our code a little. I’d recommend you open up our code in the package, and most likely copy a lot of that code into your own property drawer.
Thread bump. It’s been quite a while since this was open and I had the same issue. I am trying to create a custom editor with AddressReferences. Is there anyway to do this with the current API?
Hey guys, I believe I have come to a solution. Apparently, a dummy Scriptable Object works for this case.
public class AssetScriptable : ScriptableObject
{
public AssetReference Asset;
}
Then you can use serializedProperty to get it.
soInstance = ScriptableObject.CreateInstance<AssetScriptable>();
var serializedObject = new SerializedObject(soInstance);
var property = serializedObject.FindProperty("Asset");
Then you can use this property to draw it in your VisualElement/Imgui editor
One thing that I couldn’t figure out though, I am using IMGUIContainer for this. Because I need to get this value back to my non-serialized object’s property. But I’d rather to use a UIElements PropertyField instead. Unfortunately, there is no way to make change check for propertyfield for this, if anyone knows a way to do that, please quote me.
I couldn’t get this to work in a custom inspector. It does display the popup for Addressable, but if seemingly registers no changes no matter what you click…anyone get it to work properly?
I just tried this solution m3rt32 suggested as well in my project but like jerotas said it doesn’t seem to work for AddressableAssets. The popup appears and everything, but it doesn’t seem to register any sort of clicks.
I’m wondering if this has anything to do with GUI HotControls, perhaps? I did some digging into the AssetReferenceDrawer source code and it seems to assign those to the dropdown if I understood things correctly?
This is so close to being useful to me. In my case I’m trying to get the addressable in order to fill out some other default information on my object. Something like this:
SerializedProperty location = serializedObject.FindProperty ("location");
var val = location.objectReferenceValue;
EditorGUILayout.PropertyField (location);
if (val != location.objectReferenceValue)
{
AssetReference reference = (AssetReference) val;
serializedObject.FindProperty ("name").stringValue = reference.editorAsset.name;
}
Unfortunately, I can’t cast val to an AssetReference because it doesn’t extend Object. As far as I can tell, nothing else seems to match either. They must have some hidden voodoo going on in PropertyField. Has anyone else worked past this barrier?