New to scriptable objects and trying to use them to set certain variables throughout my project.
I’m trying to make each weapon to be a scriptable object that can access my scripts such as camera to set different values like mobility.
In creating this, I keep getting an error: shown in images.
Now, I am new to scriptable objects and relatively new to scripting. I’m wanting to use this method to prevent several hidden transforms in my game just to instantiate an object from a menu.
What is a way to script an object to override another scripts properties if need be? this is best way?
the CameraRig function is abstract in the weapon class. this means inheriting classes MUST override them, just like you are doing with Initialize. abstract means that all derived classes will have this function. and the compiler is simply complaining that WeaponStatistics didn’t override CameraRig().
one of the key things to realize about ScriptableObjects is that they usually are assets (e.g. what [CreateAssetMenu] does). Like prefabs, when they are assets they can’t save references to instances in a specific scene. sure you can store a GameObject from a scene into a ScriptableObject asset (through scripting) but it’ll appear as a “type mismatch” in the editor field, won’t be saved across scene changes, and null checking can get finicky. it’ll work but its just something to keep in mind.
it would be easier on you if you didn’t think of ScriptableObjects as accessing/calling your scripts. Instead think the opposite. have your scene scripts call on the ScriptableObjects, passing what ever data they need such as the current camera. most of the time ScriptableObjects are simply used as data containers (like weapon stats, or even game progress) and are usually devoid of any logic or decision-making. Of course you can fill with them logic but thats better left when you are more familiar with scripting.
Think plug and socket. Have a monobehaviour that is in the scene and hooked into the unity game loop (start/update/etc.) aka “the socket”. Have a scriptableObject that has your values, functions and whatever aka “the plug”. The current scene state is passed from the socket to the plug when the socket asks for something to be done. So the function calls have “Transform” or whatever as a parameter.