Accessing the public variables from the inspector of a class within a public List?

Hey guys,

Apologies for another new guy without much clue what he’s doing. I’m trying to implement a very simple dialogue system and I’me using a Sentence class which contains a string for a sentence and an int to indicate where the sentence is being spoken from in the scene.


Then I’m using a Dialogue class which is simply a List of ‘Sentence’ class objects.


The Dialogue class is attached to an interactable game object and I’d like to input values for the int and string of each ‘Sentence’ class object in the inspector of the ‘Dialogue’ component. is there any way to do so?


Dialogue class:

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

public class Dialogue : MonoBehaviour
{
    public List<Sentence> sentences;
    // Start is called before the first frame update
}

Sentence class:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Sentence : MonoBehaviour
{
    public int dialogueOrigin;
    public string sentence;
}

What I’m currently seeing in the ‘Dialogue’ component:
151919-dialoguescript.jpg

This will not be possible without with stock unity inspector as lists store references to the objects.

If you want it to work this way then you Sentence class needs to Serializable and not MonoBehaviour.

There are other ways to achieve this btw, just nothing quick and simple built in Unity. E.g. I use Odin Inspector and that can show the fields in a list. I’m not affiliated with this product, just <3 it a lot. 151921-image-19.png