I want to implement a custom AssetReferenceUIRestriction. However, my ValidateAsset
method is never called.
The code should output a message to the Console window when I drag&drop an asset on the AssetReference in the Inspector.
However, as mentioned, this method is not called, thus no message printed.
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property, AllowMultiple = false)]
sealed public class AssetReferenceUITypeRestriction : AssetReferenceUIRestriction
{
public override bool ValidateAsset(UnityEngine.Object obj)
{
Debug.Log(obj.name);
return true;
}
public override bool ValidateAsset(string path)
{
Debug.Log(path);
return true;
}
}
I then use this attribute inside my MonoBehaviour:
sealed public class Appearance : MonoBehaviour
{
[AssetReferenceUITypeRestriction()]
[SerializeField] AssetReference m_Material = null;
}
What do I have to do, to make Unity call my custom code?
I’ve looked at the AssetReferenceUILabelRestriction implementation, but the ValidateAsset methods return true always, which is also really odd, because it actually does restrict the AssetReference to the specified labels.
PS: Or is there a “Type Restriction” attribute already? I want to restrict the AssetReference to certain asset types only, such as to Materials only.
EDIT: I found AssetReferenceGameObject, but it seems there is no AssetReferenceMaterial?