Generic Scriptable Variables
Scriptable Variables for Unity2020
com.jreason.scriptablevariables 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/scriptablevariables.git?path=Assets/ScriptableVariables README Markdown
Copy this to your project's README.md
## Installation
Add **Generic Scriptable Variables** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/scriptablevariables.git?path=Assets%2FScriptableVariables
```
[](https://www.pkglnk.dev/pkg/scriptablevariables)README
Generic Scriptable Variables
Scriptable Variables is package to implement variables in Unity using Scriptable Objects, taking advantage of Unity 2020.1 ability to serialize generic fields.
Warning
This package is considered to be a preview-package. This means:
- Core features may be incomplete.
- Functionality has not yet been fully tested and definitely contains bugs.
- Documentation is incomplete.
- Code may be uncommented and not following standards
System Requirements
Unity 2020.1.0 or later versions.
Installation
The package is available on the openupm registry at com.jreason.scriptablevariables.
More information can be found at the Installation page.
Usage
There are two main classes in the package: Variable<> and Reference<>
Variable
Variables are assets created in the Unity Editor which store data. A new Variable Asset can be created from the 'Assets/Create/Variable' menu or from the '+' Dropdown in the ProjectView. A Variable's type can be changed in the 'Type' Dropdown.
Variable Types
Before being able to create a Variable Asset of a certain Type, that type needs to be created as a Class.
The nessary code to create a Variable type can generate from the 'Type' Dropdown by clicking 'Create new', this only needs to be done once per type.
Some Types are pre-setup such as primitives and some more common Unity classes.
Reference
References are how variables are accessed in Code.
(e.g. Use Reference<float> to reference a Float Variable.)
//Reference to Vector3 Variable
public Reference<Vector3> m_direction;
private void Update()
{
//How to set the value of the variable
m_direction.Value = transform.forward;
//Can implicitly cast when getting the value of the variable
transform.position += m_direction;
//Sometimes you'll need to do this though
transform.position += m_direction.Value * Time.deltaTime;
transform.position += (Vector3)m_direction * Time.deltaTime;
}
More information can be found in the Variable page and Reference page
Credits
- The theory for this package is based off Ryan Hipple's Unite Talk.
- The code is based off Wolar-Games Implementation and has been re-written for Unity 2020.1.
No comments yet. Be the first!