Variable Reference
Scriptable Variable
Last updated
Scriptable Variable
Last updated
Instead of exposing a reference to a ScriptableVariable, you can use a Variable Reference:
A variable reference allows you to choose between a local value or a ScriptableVariable.
You might want to use a VariableReference instead of a ScriptableVariable when you aren't sure if you will want to use a ScriptableVariable for a specific variable.
For example, I have a script called Car.cs and I want to expose the speed float variable. I'm not sure yet if I want to use a FloatVariable or just a float. Therefore, I can expose a FloatReference. Then in the inspector, if I choose 'Use Local', I can input a value as if it were a normal float. If later I want to access/modify the speed from other classes, I can create a FloatVariable called float_speed, change to 'Use Variable' in the Car component from the inspector, and drag my new FloatVariable.
This can also be useful if you have multiple objects that share the same components. Let’s say you have different cars that share the same Car.cs component. Each AI car can use 'Use Local' with a predefined value, while the player car can 'Use Variable' and have it linked to a FloatVariable, making it flexible.