Question about How we did Actions

We have all BaseActions as component instances. I’m working on a UI for this game to allow the player to select actions from a list.

Right now Actions are a bunch of component instances because they use Update() Start() and other Monobehavior lifecycles. I want to be able to have an action on a scriptable object. What’s the best way to do this?

I’m thinking of having each action be it’s own prefab and then list all those prefabs on a scriptable object to itterate over. Is this a bad approach? Are there better approaches?

Placing the Actions on a scriptableObject requires that we provide the lifecycle events for the ScriptableObject. The nice part of this is that you only need to be running an Update() on one ScriptableObject at a time.

There are a couple of considerations, however. Since ScriptableObjects are shared resources, every character with a reference to the ScriptableObject shares the same data. This means you’ll need to pass the User along the Update method, probably along with some state. Alternatively, you could Instantiate the ScriptableObjects for each character that uses them.

Making a prefab with a MonoBehaviour for that Action logic and then just storing that prefab in the Scriptable Object is indeed one way to do it.
You would store a List of ActionSO on the Unit, then on Awake cycle through that list and instantiate all the prefabs for all the actions.

Like Brian mentioned technically you can write functions directly on the SO so you could add an Update(); there to run the logic, but be very aware that if you share SO (like 2 units have the same Action) then they would share the state on that SO.
On option is indeed to Instantiate that SO to create a copy. Although personally I don’t like using SOs for this purpose, I prefer to use them solely as read-only data containers.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms