ScriptableObject Inheritance

My script, Communication, uses function UpdateDialogue with three ScriptableObject types.

ComplexDialogue inherits from AdvancedDialogue, and AdvancedDialogue inherits from BasicDialogue.

My monobehavior script:

public void UpdateDialogue(ScriptableObject dialogue)
{
//Debug.Log("UpdateDialogue");
currentString = 0;



if (dialogue is ComplexDialogue)
{ 

}
else if (dialogue is AdvancedDialogue)
{ 

}
else if (dialogue is BasicDialogue)
{ 

}

It works, but I feel like there’s a smarter way to go about this?

Let me know if you need more info, thanks!!!

This doesn’t feel like a good use of OOP - instead it would make much more sense to keep all dialogue relative function within the dialogue classes themselves and override from the parent;

public class BasicDialogue : ScriptableObject
{
    // 'virtual' means that we can override the implementation in child classes
    public virtual void UpdateDialogue (Communication a_Communication)
    {
        // Your basic dialogue code goes in here
    }
}

public class AdvancedDialogue : BasicDialogue
{
    // Now override the UpdateDialogue function to change what it does for AdvancedDialogue
    public override void UpdateDialogue (Communication a_Communication)
    {
        // Your advanced dialogue code goes here
    }
}

public class ComplexDialogue : AdvancedDialogue
{
    public override void UpdateDialogue (Communication a_Communication)
    {
        // Your complex dialogue code goes here
    }
}

Then, you can just pass in the dialogue as a BasicDialogue and call the UpdateDialogue() function and the runtime will choose the appropriate implementation based on the object type;

public class Communication
{
    public void UpdateDialogue (BasicDialogue a_Dialogue)
    {
        // a_Dialogue can be of any type that inherits from BasicDialogue
        a_Dialogue.UpdateDialogue (this);
    }
}

Re-routing through the Communication class also seems unnecessary, but not knowing what you are using these systems for, I can’t say.