I’m trying to create a generic class called Value from which I can get a local class or the same type of class from a ScriptableObject.
Here is a snippet of the code
using NaughtyAttributes;
using UnityEngine;
[System.Serializable]
public class Value <T> {
[SerializeField] bool isLocal = true;
[SerializeField, AllowNesting, ShowIf (nameof (isLocal))] T value;
[SerializeField, AllowNesting, HideIf(nameof(isLocal))] ValueSO<T> scriptableObject;
// Getter
public T Get() {
if (isLocal) {
return value;
} else {
return scriptableObject.value;
}
}
}
using UnityEngine;
public class ValueSO<T> : ScriptableObject {
[SerializeField] public T value;
}
These are 2 examples of Scriptable Objects that would use the Generic class
using UnityEngine;
public class RecoilStatsSO : ValueSO<RecoilStats> {}
using UnityEngine;
public class ModeStatsSO : ValueSO<ModeStats> {}
Everything works as expected until here. The issue I’m having is that when using the fields as non-local (so they use a scriptableObject) the Unity Asset selection UI shows all ScriptableObjects that use the Generic ValueSO class instead of showing only the ones with the specified
using UnityEngine;
public class Test : Monobehaviour {
public class Value <RecoilStats> recoil;
public class Value <ModeStats> mode;
}
Oh ok haha! I just found this other thread that addresses the same issue I’m having and it’s almost 2 years old. So it seems to be a bug and Unity doesn’t seem to have any interest in fixing it