How to change existing inspector functionality towards deleting from Lists?

I’m creating a dialogue system but I can’t seem to figure out how to remove any unused previously deleted nodes that are saved to the Dialogue scriptable object asset from the default inspector. In the photo, if you press the - button in the custom inspector node

9886839--1426833--upload_2024-6-12_7-45-34.png

It properly deletes the sub assets which appear here.

9886839--1426836--upload_2024-6-12_7-46-16.png

However in unity’s built in inspector on the right if I push the - button, it does NOT delete the existing node in the bottom as this photo shows.

How would I go about changing how the existing inspector treats the - button. Or am I stuck with the inspector not cleanly deleting existing objects from the assets.

here is how I treat the - button on the nodes. This entire section of code is wrapped in an #if UNITY_EDITOR
to ensure only the editor can change dialogue nodes.

public void DeleteNode(DialogueNode nodeToDelete)
{
    Undo.RecordObject(this, "Deleted Dialogue Node");

    nodes.Remove(nodeToDelete);

    string path = "Resources/Dialogue/" + _name + ".asset";

    AssetDatabase.RemoveObjectFromAsset(nodeToDelete);

    OnValidate();
    CleanDanlgingChildren(nodeToDelete);
    Undo.DestroyObjectImmediate(nodeToDelete);
}

You’ll want to create a custom inspector for this scriptable object, and either just omit drawing the list (which can also be done with the [HideInInspector] attribute), or draw the list yourself with the necessary custom implementation. This will be easier to do with UI Toolkit.

More info here: Unity - Manual: Create a Custom Inspector

It is a bit of a deep topic if you’ve never stepped into it before.

Alternatively, consider whether you can use plain C# objects in lieu of scriptable object sub assets.

1 Like