I’m hoping someone can please give me some insight into resolving my issue. It’s to do with polymorphism; more specifically, it’s showing variables in a custom inspector for a given class whose variables are not known in advance. Bit of a mouthful.
Let me give you an example of what I am trying to do.
If I were to have the following MonoBehaviour class:
public class Example : MonoBehaviour
{
[SerializeField]
private Task[] tasks;
...
}
With the following abstracted Task class inheriting from ScriptableObject:
[System.Serializable]
public abstract class Task : ScriptableObject
{
[SerializeField]
private int baseInt;
public abstract void SomeFunction();
}
In the Editor script for the Example class, I have a few lines which essentially creates an ObjectField whereby a MonoScript of a class inheriting from the abstracted Task class can be dragged in. The Editor script will create an instance of the dragged in class and save it as an asset. When it comes to displaying variables for this instantiated class, I can display the guaranteed baseInt variable and allow an input box for it, but I can’t figure out a way to display input boxes for the child class variables.
If I had the child class:
[System.Serializable]
public class Action : Task
{
[SerializeField]
private int actionInt; // How I display you in inspector!?
...
}
Is there a way to detect if this child class has serialized variables, and then for each one of those serialized variables display an input box for it of the correct type? Or is this something that would cause a big headache?
I know I can get the actionInt through using the FindPropertyRelative() function, but that requires knowing what the variable is called. What if it was a child class that had different variables of potentially different types?
I hope I have explained my issue well enough - and thank you in advance!