I have a script that holds public variables for other scripts to access. I never thought I’d need such a thing, but here we are.
So, the class is literally empty except for a public variable (and a ‘using’ namespace to let me have that variable) so really I don’t need the class to extend from monobehavior, do I? The script isn’t using anything I get from monobehavior except for the ability to attach it to a gameObject.
What other options are there for classes I can extend from? Just to shave a little bit of overhead off of my game…
Dang, I still need it to attach to a gameObject though, I got a bunch of errors when I tried to change it to ScriptableObject.
The game object exists in the scene and also has a collider on it; I’m using Physics.OverlapSphere on another object so I can get a reference to a path in my scene as suggested in this thread.
Is there another level of class that can still attach to a game object?
Yes, but I’m doing this to set up objects I DON’T have in my scene; I’m instantiating some enemies at run-time and I need them to see a reference to a path that they will follow.
My solution was to put a trigger collider near where they spawn, and have the enemy use overlapSphere to find this, and then grab the path reference from them.
Well we didn’t know that at the beginning of the thread.
Scriptable Objects exist at the asset level, and they can’t serialise reference to scene-level objects (but can store nonserialised references to them at run time).
For storing references to stuff at the scene level, yes Monobehaviour’s are what you need.
Also I wouldn’t worry too much about having small monobehaviours that hold small amounts of data. If they aren’t running anything in update then it’s just memory waiting to be accessed. It is a component based game-engine after all. Used it for what it’s good for!
Why nost just have a static class? I use them for constants and such stuff. Some will say “globals are bad” but when you know their constraints what could go wrong? Seriously. Don’t overcomplicate things. When there is a quick and easy solution to a problem use it. When you encounter problems/issues you can change it.