Hi,
I have a derived class that I’m serializing. If I check the value in code, it says it’s null. But if I inspect the value it actually has a value. See attached image. Can anyone tell me what’s causing this?
As you can see, the if-check succeeds and the for-loop is short-circuited with a ‘continue’, however ‘item’ actually has a value, the value that I’d expect it to have.
[Serializable]
public class ScriptableActionsAsset : NarrationScriptableObject
{
[SerializeField]
public ScriptableActionItem[] Items;
}
[Serializable]
public class PlayAudioActionItem : ScriptableActionItem
{
[SerializeField]
public AudioClip pathToAudioClip;
}
[Serializable]
public class ScriptableActionItem : ScriptableObject
{
}
I realise that the [Serializable] attributes are a bit redundant, but I had them in initially and haven’t removed them yet. The ScriptableActionItem and NarrationScriptableObject contains methods but no data, they both extend ScriptableObject.
The ScriptableActionsAsset is a property on a MonoBehaviour. The Start() method of MonoBehaviour (attached to a GO) runs the following method:
public void ConvertActionItems(GameObject target, IList items)
{
foreach(ScriptableActionItem item in items)
{
if (item == null)
{
continue;
}
var scriptableItem = item.ToAction(target);
Actions.Add(scriptableItem);
}
}