Search code examples
c#unity-game-enginescriptable-object

Is a Mouse Manager as a ScriptableObject viable?


I am trying to wrap my head around ScriptableObjects and their possibilities. My goal is to have a Mouse Manager that keeps track of the mouse position, objects it's hovering over, and other behaviors. I want this manager to be read by anything that wants to know whenever it wants to know it.

I know I could make a MonoBehavior script that has ScriptableObject Variables (like a Vector3) that it keeps updated, but that requires me to add the manager to each scene manually. And then I would need to include each variable as a reference into any other asset that needs to read it.

Is there a better way to do this? Have the manager as a ScriptableObject, each attribute also a ScriptableObject, and just reference the manager in whatever script needs access to it?


Solution

  • From unity docs:

    The main use cases for ScriptableObjects are:

    • Saving and storing data during an Editor session
    • Saving data as an Asset in your Project to use at run time

    I don't think that what you want to achieve is possible, since things like mouse position change at runtime. However I believe that creating a MonoBehavior script should work fine. Since it needs to be on every scene, you could make use of prefabs and DontDestroyOnLoad.