AutoPopulated AssetList with CustomFilterMethod - Force refresh?

Issue #559 new
Kristijan Trajkovski created an issue

Hi,
We’re trying to make a small tool that would allow us to pick an asset kit and easily swap out the mesh of an object. Our artist should pick the location where the kit he wants to use is located, and the AssetList should only show objects located there. My initial thought was - We’re going to use an attribute expression to read from the KitLocation, but that doesn’t seem to work on AssetLists. My next solution was to do a CustomFilterMethod to filter based on the location of the assets. However, we’re having the following issue.
If the KitLocation is changed, the KitAsset doesn’t change. How can we force a new AutoPopulation?

using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

public class KitList : MonoBehaviour
{
  [FolderPath]
  public string KitLocation;
  [AssetList(CustomFilterMethod = "ObjectInKitLocation", Path = "/Prefabs/Kits/", AutoPopulate = true)]
  [InlineEditor]
  public GameObject KitAsset;

#if UNITY_EDITOR
  // Check if given GameObject is in KitLocation
  bool ObjectInKitLocation(GameObject go)
  {
    return AssetDatabase.GetAssetPath(go).StartsWith(KitLocation, System.StringComparison.Ordinal);
  }
#endif
}

Thanks,
Kristijan

Comments (1)

  1. Log in to comment