{"id":25791136,"url":"https://github.com/yanicksenn/unity-variables","last_synced_at":"2026-05-14T15:36:02.593Z","repository":{"id":134783740,"uuid":"457836633","full_name":"yanicksenn/unity-variables","owner":"yanicksenn","description":"Unity3d package allowing the distribution of data between different GameObjects through ScriptableObjects.","archived":false,"fork":false,"pushed_at":"2024-01-07T22:14:36.000Z","size":24097,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-27T16:26:14.523Z","etag":null,"topics":["game-development","open-source","unity","unity3d"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yanicksenn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-02-10T15:28:53.000Z","updated_at":"2022-03-19T21:33:43.000Z","dependencies_parsed_at":"2023-05-25T16:45:13.734Z","dependency_job_id":null,"html_url":"https://github.com/yanicksenn/unity-variables","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/yanicksenn/unity-variables","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanicksenn%2Funity-variables","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanicksenn%2Funity-variables/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanicksenn%2Funity-variables/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanicksenn%2Funity-variables/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yanicksenn","download_url":"https://codeload.github.com/yanicksenn/unity-variables/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yanicksenn%2Funity-variables/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33031269,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-13T13:14:54.681Z","status":"online","status_checked_at":"2026-05-14T02:00:06.663Z","response_time":57,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["game-development","open-source","unity","unity3d"],"created_at":"2025-02-27T12:54:42.637Z","updated_at":"2026-05-14T15:36:02.574Z","avatar_url":"https://github.com/yanicksenn.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Variables\nUnity3d package allowing the distribution of data between different GameObjects through ScriptableObjects.\n\nThis project is inspired on the [presentation](https://youtu.be/raQ3iHhE_Kk?t=926) by [Ryan Hipple](https://twitter.com/roboryantron).\nI added my own flair to it by adding simple property drawers and extendability for custom and complex variables.\n\nFeedback is welcome.\n\n## Plug and Play\n1. Open \"Package Manager\"\n2. Choose \"Add package from git URL...\"\n3. Use the HTTPS URL of this repository:\n   `https://github.com/yanicksenn/unity-variables.git`\n4. Click \"Add\"\n\n## Usage\n- [References](#user-content-references)\n- [Variables](#user-content-variables)\n- [Customization](#user-content-customization)\n\n### References\nThis package provides you references and variables.\nReferences are used in the scripts to allow access to a constant or variable.\n\nThese are the build-in references and the corresponding variables:\n\n| Reference             | Variable               |\n|-----------------------|------------------------|\n| `FloatReference`      | `FloatVariable`        |\n| `\"`                   | `ClampedFloatVariable` |\n| `IntReference`        | `IntVariable`          |\n| `\"`                   | `ClampedIntVariable`   |\n| `BoolReference`       | `BoolVariable`         |\n| `StringReference`     | `StringVariable`       |\n| `Vector2Reference`    | `Vector2Variable`      |\n| `Vector3Reference`    | `Vector3Variable`      |\n| `QuaternionReference` | `QuaternionVariable`   |\n\nNobody hinders you from directly using variables inside of your scripts.\nPlease keep in mind then the interchangeability of constant and variable is not possible.\n\nYou can use them inside of your scripts. You don't need to call the constructor but if you do you can provide a default value for your constant.\n\n```c#\npublic class MyBehaviour : MonoBehaviour\n{\n    public FloatReference myFloat;\n    // public FloatReference myFloat = new FloatReference(7.2f);\n}\n```\n\nThe button ![Button](./Documentation/button.png) is drawn in front you your reference.\n\n![Reference with constant](./Documentation/example-behaviour-constant.png)\n\nIf you click on it, a popup with be displayed providing you with the options of using the variable or a the constant.\n\n![Reference with constant](./Documentation/example-behaviour-popup.png)\n\nAfter choosing the variable the property will immediately be updated to allow referencing a variable. Vice versa if you choose to use the constant.\n\n![Reference with variable empty](./Documentation/example-behaviour-variable-empty.png)\n\nYou can read and write to your references through the `myFloat.Value` property.\n\nAdding the `Start` method to the behaviour ... \n```c#\nvoid Start() {\n   myFloat.Value = 99.876f;\n   Debug.Log(myFloat.Value);\n}\n```\n\n... will result in the following console output.\n\n![Console](./Documentation/console.png)\n\n### Variables\nVariables can be created through the asset menu \u003e Create \u003e Variables \u003e ... .\n\n![Asset menu](./Documentation/asset-menu.png)\n\nAfter assigning the created variable to the behaviour you should see a preview with value of the variable.\n\n![Asset menu](./Documentation/example-behaviour-variable-filled.png)\n\n### Customization\nIt is possible to create you own reference and variable by extending from `AbstractReference` and `AbstractVariable`.\nMostly you will just have to create boilerplate code.\n\n#### Data\nStart by defining a data class. It is important that this `class` or `struct` is annotated with `Serializable`.\n```c#\n\n// Arbitrary data object \n[Serializable]\n public struct Character\n {\n     public string name;\n     public int age;\n     public float height;\n     public BoolReference alive;\n     public Pet pet;\n }\n \n // Arbitrary example of a nested object\n [Serializable]\n public class Pet\n {\n     public string name;\n     public int age;\n     public BoolReference alive;\n }\n```\n\n#### Event (Boilerplate)\nCreate an event with the type of the data class as payload. This is just boilerplate code.\n```c#\n[Serializable]\npublic class CharacterEvent : UnityEvent\u003cCharacter\u003e { }\n```\n\n#### Variable (Boilerplate)\nCreate a variable class by extending from `AbstractVariable` (inherits from `ScriptableObject`). This is just boilerplate code.\n```c#\n[CreateAssetMenu(\n     menuName = Variables.RootMenu + \"/Create Character variable\",\n     fileName = \"Character\")]\npublic class CharacterVariable : AbstractVariable\u003cCharacter, CharacterEvent\u003e { }\n```\n\n#### Reference (Boilerplate)\nCreate a reference class by extending from `AbstractReference`. This is just boilerplate code. It is possible to provide a default constant value inside of the constructor.\n```c#\n[Serializable]\npublic class CharacterReference : AbstractReference\u003cCharacter, CharacterVariable, CharacterEvent\u003e\n{\n    public CharacterReference(Character defaultConstantValue) : base(defaultConstantValue) { }\n}\n```\n\n#### Drawer (Boilerplate)\nCreate a drawer class by extending from `AbstractSimpleReferenceDrawer`. This is just boilerplate code.\n```c#\n[CustomPropertyDrawer(typeof(CharacterReference))]\npublic class CharacterReferenceDrawer : AbstractSimpleReferenceDrawer { }\n```\n\n#### Example\nUse the new `CharacterReference` inside of your `MonoBehvaiour` or `ScriptableObject`.\n```c#\npublic class CharacterBehaviour : MonoBehaviour {\n    public CharacterReference character;\n}\n```\n\n#### Example in inspector\n\nUsing the `CharacterBehaviour` on a `GameObject` would then show the following editor in the inspector, allowing you to edit the underlying constant.\n\n![Editing the constant](./Documentation/custom-constant.png)\n\nOr if you want to reference a variable.\n\n![Editing the variable](./Documentation/custom-variable.png)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanicksenn%2Funity-variables","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyanicksenn%2Funity-variables","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyanicksenn%2Funity-variables/lists"}