How to take data from a Class in a ScriptableObjects

I have created two classes in a ScriptableObject:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
    [SerializeField] Context[] context;
    [SerializeField] Decisions[] decisions;

    [System.Serializable]
    public class Context
    {
        [TextArea(14, 10)] [SerializeField] string contextText;
        [SerializeField] Sprite contextImage;
    }

    [System.Serializable]
    public class Decisions
    {
        [TextArea(3, 2)] [SerializeField] string decisionText;
        [SerializeField] string jumpTo;
    }
}

I want to access to the data stored in the arrays, using a return method but i dont know how.

Just make all of the fields public. Is there a reason they are private?

1 Like

Humm i thought all was public, but i dont know how to do that.

in C# all fields are private by default, you have to manually make them public.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[CreateAssetMenu(menuName = "State")]
public class State : ScriptableObject
{
    [SerializeField] public Context[] context;
    [SerializeField] public Decisions[] decisions;

    [System.Serializable]
    public class Context
    {
        [TextArea(14, 10)] [SerializeField] public string contextText;
        [SerializeField] public Sprite contextImage;
    }

    [System.Serializable]
    public class Decisions
    {
        [TextArea(3, 2)] [SerializeField] public string decisionText;
        [SerializeField] public string jumpTo;
    }
}
1 Like