If I want to be able to reference a clip in an addressable that happens to be inside an FBX this doesn’t seem to be possible. Rather, you can, but in order to do so you have to use AssetReferenceGameObject and then point at the sub asset. This is counter-intuitive as AssetReferenceAnimationClip should be the containing type. Using this doesn’t work however because it expects the mainAsset to be an AnimationClip. If you’re setting a subAsset then editorAsset should not be checking the main asset to match the type.
BUMP. This is still the case in 1.9.2. Are there any plans to change / fix this? It’s definitely not a limitation of the Addressables system as I’ve forked my own version that allows it to work correctly.
1.16.1 - Same issue. An AssetReferenceT should allow you to pick any main asset that matches TYPE or show you sub assets that match TYPE and auto fill the parent object. Is there a technical reason this isn’t being done?
EDIT: “fill the child object” replaced with “fill the parent object”
I’ll send this over to see what response I can get for you @KAJed !
We’ve made a ticket to look into this. Thanks for the feedback!
Has any progress been made on this?
Let me touch base with the team on the status of this.
I think this was fixed, you can try 1.16.15 and see. If it isn’t please report a bug through the Unity bug reporter. It’ll help us make sure we fix the correct issue.
Still not fixed. I’m putting together a minimal repro bug report.
Case 1298553
Gotcha. Thanks for the update, and for putting in the Bug Report!
I received an email this morning in response to the issue which does not accurately represent the problem or the solution.
“The behaviour you are experiencing is expected since the constructor for class AnimationClipReference : AssetReferenceT requires a GUID as a parameter, but a Sub-Asset does not have one.”
I have responded, but could you please ensure this issue gets seen by the correct team before it is closed prematurely.
Hey everyone.
Just to let you know that this has been implemented. The feature should be available in 1.17.5-preview+.
Don’t hesitate if there’s anything else.
Exciting! I look forward to taking it for a test drive.
It looks like there are some weird use case limitations with the current 1.17.5 preview. Namely, editorAsset doesn’t actually return the subobject. Call it while the main asset is not the correct type leads to a log (should be a warning?) that the object cannot be cast to the expected type.If the sub asset isn’t set though the editor should clearly state that current main object is not valid.
Expected behaviour #1: if the main asset is not set to the correct type (and the SubObjectName isn’t set) it should return null not an error.
Expected behaviour #2: if the sub object name is set then editorAsset should return the sub asset that is being referenced. As it is I ended up having to write an extension method that does that extra “find me the correct sub object” step. This should not be expected of the end-user.
My current extension to play with this:
public static bool TryGetEditorAsset<TAssetReference, T>( this TAssetReference assetRef, out T value )
where TAssetReference : AssetReference
where T : Object
{
value = default( T );
if ( assetRef == null )
return false;
if ( !string.IsNullOrWhiteSpace( assetRef.SubObjectName ) )
{
var subAssets = AssetDatabase.LoadAllAssetRepresentationsAtPath( AssetDatabase.GUIDToAssetPath( assetRef.AssetGUID ) );
foreach ( var s in subAssets )
{
if ( s != null && s.name == assetRef.SubObjectName && typeof( T ).IsAssignableFrom( s.GetType() ) )
{
value = (T)s;
return value != null;
}
}
return false;
}
Object untypedEditorAsset = assetRef.editorAsset;
if ( untypedEditorAsset == null || !typeof( T ).IsAssignableFrom( untypedEditorAsset.GetType() ) )
return false;
value = (T)assetRef.editorAsset;
return value != null;
}
Apologies for the delay.
If I remember correctly, there was a reason why editorAsset is currently only returning the main asset. But your logic is sound, it makes sense that the editorAsset property of an AssetReference returns the asset it’s referencing even if it is set to a sub-asset. I’ll need to refresh my memory on this a bit and investigate.
I’ll get back at you as soon as possible.
I didn’t really have time to investigate this yet, but I’ve created a ticket for it until we evaluate the implications of changing this behavior.
Thank you for sharing your extension method to the community.