🧼
Soap - 3.5.1
  • Getting Started
    • What is Soap?
    • Why use Soap?
    • Where to get Soap?
  • Soap Core Assets
    • Scriptable Variable
      • Properties
      • Debugging
      • Variable Reference
      • Runtime Variables
      • FAQ
    • Bindings
    • Scriptable List
      • Properties
      • Callbacks
      • FAQ
    • Scriptable Event
      • Properties
      • Debugging
      • FAQ
    • Event Listener
      • Properties
      • Dynamic Binding
      • FAQ
    • Scriptable Enum
      • Creating new Enum Values
      • Adding Data
    • Scriptable SubAssets
      • Creating/Deleting SubAssets
      • Accessing SubAssets
      • FAQ
    • Scriptable Save
      • Properties
      • FAQ
    • Scriptable Dictionary
      • Properties
      • Callbacks
      • Custom Dictionary Creation
      • FAQ
    • Runtime Injectors
  • Useful Tips
    • Creating Soap ScriptableObjects
      • Soap Asset Creator
      • From Create Shortcut
      • Default Unity Create Menu
    • Using Tags
      • AutoTag Attribute
    • Finding References
    • Editor Fast Play Mode
    • Addressables
      • Solutions
  • Custom Windows
    • Soap Wizard
      • Shortcuts
    • Soap Window
      • Settings
    • Soap Type Creator
    • Soap Asset Creator
  • Quality
    • How to extend Soap?
    • Performance
    • Integration with other assets
    • Games using Soap
    • Suggestions
  • Scene Documentation
    • 1_ScriptableVariables
      • Direct Access
      • OnValueChanged Event
      • Variable Reference
      • Solving Dependencies
      • Saving Variable Values
      • Save Exercise
      • Menu Context Option
    • 2_Bindings
      • BindText/TextMeshPro
      • BindFillingImage
      • BindSlider
      • BindToggle
      • BindGraphicColor
      • BindRendererColor
      • BindComparisonToUnityEvent
      • BindInputField
    • 3_ScriptableLists
      • Adding & Removing Elements
      • Callbacks
      • Auto Clearing
      • Iteration
    • 4_ScriptableEvents
      • Firing Events from code
      • Event Listeners
      • Registering to events from code
      • Firing events from the editor
      • Debugging
    • 5_ScriptableSaves
      • Save Data
      • Useful Methods
      • Save/Load Modes
      • Save Reader
      • Save Manager
      • Save Version
    • 6_ScriptableEnums
      • Scene Setup
      • How does it work?
      • Additional Data
      • Exercise
    • 7_ScriptableSubAssets
      • Scene Setup
      • Direct Reference
      • Indirect Reference
    • 8_RuntimeVariables
      • Manual Injection
      • Flexibility
      • Automatic Injection
    • 9_ScriptableDictionaries
      • Scene Set up
      • Adding & Removing Elements
      • Callbacks
      • Custom Inspector
Powered by GitBook
On this page
  1. Soap Core Assets
  2. Scriptable Variable

Variable Reference

Scriptable Variable

PreviousDebuggingNextRuntime Variables

Last updated 8 months ago

Instead of exposing a reference to a ScriptableVariable, you can use a Variable Reference:

public class MyCustomClass : MonoBehaviour
{
    [SerializeField] private FloatReference _floatReference;
}

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.