Question About Custom Inspectors And Sciptable Objects

Hi, I have a designing problem and couldn’t solve it by myself.

public abstract class Action
{
     public int actionID;
     public string actionName;
     public Status actionStatus;

     protected virtual void Activate()
     {
            actionStatus = Status.Active;
     }

     protected virtual void Execute()
    {
          if(actionStatus == Status.Inactive)
               Activate();
    }

    protected virtual void Reset()
    {
          actionStatus = Status.Inactive;
    }
}

I have action’s that derived from this class, and each one have own Activate, Execute and Reset functionalities. Like this;

public class Action_Use : Action
{
     protected override void Activate()
     {
            base.Activate();

            // Action_Use specific activations
     }

     protected override void Execute()
    {
          base.Execute();

            // Action_Use specific executions
    }

    protected override void Reset()
    {
          base.Reset();

          // Action_Use specific reset
    }
}

Some gameobjects in my game has behaviours and this behaviours have own their action list.

public abstract class Behaviour : ScriptableObject
{
     public List<Action> actionList;

     //
}

When I inherit Action from Scriptable Object I can create those actions from menu and add them into behaviours.

But when the actions and behaviours are being used by game objects in runtime, properties of scriptable objects are change(for example if one game object changed action status to active, then the other game objects that uses same action’s status also change) and this is not what I want.
I want a solution that I can easily add this actions to the behaviours, and game objects can change this actions’ properties individually.

Can I solve this problem with scriptable objects(but different way that current implementation) or I have to use custom inspector(reordarable lists, property drawers etc.)?

Thanks in advance.

The easiest thing is to just make a copy of the ScriptableObjects at startup:

for (int i = 0; i < actionList.Length; i++)
    actionList[i] = Instantiate(actionList[i]);

This does of course have an overhead in memory footprint and startup time, but if you only have a few dozen of these, it shouldn’t be a problem

1 Like

Hmm, thank you for answering. I will try this today.