{"id":13662275,"url":"https://github.com/Moolt/UnityRuntimePresets","last_synced_at":"2025-04-25T07:31:07.867Z","repository":{"id":54354444,"uuid":"165912598","full_name":"Moolt/UnityRuntimePresets","owner":"Moolt","description":"Creating presets and using them in the compiled game.","archived":false,"fork":false,"pushed_at":"2019-09-23T20:40:58.000Z","size":184,"stargazers_count":45,"open_issues_count":0,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-11-10T17:46:51.821Z","etag":null,"topics":["editor","presets","runtime","unity"],"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/Moolt.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}},"created_at":"2019-01-15T19:42:52.000Z","updated_at":"2024-10-31T14:57:47.000Z","dependencies_parsed_at":"2022-08-13T13:10:28.111Z","dependency_job_id":null,"html_url":"https://github.com/Moolt/UnityRuntimePresets","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moolt%2FUnityRuntimePresets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moolt%2FUnityRuntimePresets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moolt%2FUnityRuntimePresets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Moolt%2FUnityRuntimePresets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Moolt","download_url":"https://codeload.github.com/Moolt/UnityRuntimePresets/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250774683,"owners_count":21485200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["editor","presets","runtime","unity"],"created_at":"2024-08-02T05:01:54.133Z","updated_at":"2025-04-25T07:31:07.861Z","avatar_url":"https://github.com/Moolt.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# What are (runtime) presets?\n\nPresets are a way to store a components values to an asset file that can be reapplied to other components either in the [editor](https://docs.unity3d.com/Manual/Presets.html) or by [scripting](https://docs.unity3d.com/2018.2/Documentation/ScriptReference/Presets.Preset.html).\n\nPresets have one downside though: They are placed in the `UnityEditor` namespace and can therefore not be used in your compiled game. Loading presets at runtime is unfourtunately not possible. This plug-in intends solve this problem.\n\nRuntime presets are an alternative to the Unity presets by storing components as prefabs that can then be reapplied at runtime. Using runtime presets is nearly identical to using the default Unity presets:\n\n```csharp\npublic class ApplyPreset : MonoBehaviour\n{\n    public Preset _preset;\n    public Light _light;\n\n    private void Awake()\n    {\n        _preset.ApplyTo(_light);\n    }\n}\n```\n## Setup\n\nIf you want to get a quick overview you should check out the [demo project](https://github.com/Moolt/UnityRuntimePresets/archive/master.zip). \nYou can also download the [package](https://github.com/Moolt/UnityRuntimePresets/raw/master/runtimePresets.unitypackage) containing only the essential scripts.\n\nAfter downloading and importing the package, you will find a new entry `Create Runtime Preset` in the gear menu ![alt text](https://github.com/Moolt/UnityRuntimePresets/raw/master/Documentation/gear_icon.png \"gear icon\") of a component.\n\n## Creating a runtime preset\n\nOpen the gear menu ![alt text](https://github.com/Moolt/UnityRuntimePresets/raw/master/Documentation/gear_icon.png \"gear icon\") on any GameObjects component and click `Create Runtime Preset`.\n\n![alt text](https://raw.githubusercontent.com/Moolt/UnityRuntimePresets/master/Documentation/creating_preset.png \"creating runtime preset\")\n\nThe plug-in will then create the preset in the `Assets` folder. A newly created preset will always have the default name `New Preset`. Rename it after creation to prevent it from being overwritten.\n\n![alt text](https://raw.githubusercontent.com/Moolt/UnityRuntimePresets/master/Documentation/preset_prefab.png \"preset file\")\n\nThe preset is simply a prefab with a copy of your selected component. It also has an additional component called `Preset`. Keep this in mind as we'll need it in the next step.\n\n![alt text](https://raw.githubusercontent.com/Moolt/UnityRuntimePresets/master/Documentation/preset_component.png \"preset detail\")\n\n## Loading runtime presets\n\nPresets can be set in the inspector once you expose a variable of the `Preset` type.\n\n```csharp\npublic class ApplyPreset : MonoBehaviour\n{\n    //A preset which needs to be set in the inspector\n    public Preset _preset;\n    //A light component that we want to modify\n    public Light _light;\n\n    private void Awake()\n    {\n        //Presets store values of a specific component type\n        //Checking whether the values can be applied may be helpful\n        if(_preset.CanBeAppliedTo(_light))\n        {\n            //Transfers the values from the preset onto the _light component\n            _preset.ApplyTo(_light);\n        }\n    }\n}\n```\n\nAfter compiling the script you can now set the preset and reference the light component. The `preset` field is restricted to only accepting `presets`. You won't accidentally reference something else than a `preset`.\n\n![alt text](https://raw.githubusercontent.com/Moolt/UnityRuntimePresets/master/Documentation/script_with_preset.png \"script inspector\")\n\n## Creating presets during runtime\n\nPresets can also be created during runtime. You will need any component to initialize the preset with. The preset can then be used to apply the values to any component of the same type.\n\n```csharp\npublic class CreatePreset : MonoBehaviour\n{\n    //A reference to a light from another gameObject\n    public Light otherLight;\n    //The preset we want to store the lights values in    \n    private Preset _preset;\n\n    void Start()\n    {\n        //Getting the light component of this gameObject\n        var light = GetComponent\u003cLight\u003e();\n        //Create a new preset from \"otherLight\" and apply its values to \"light\"\n        _preset = Preset.From(otherLight);\n        _preset.ApplyTo(light);\n        //Removes the temporary object created to store the runtime preset\n        //This is optional\n        _preset.Free();        \n    }\n}\n```\n\nThe examples might be a bit forced, but I often find myself in more complex situations where runtime presets can be a real life saver.\nI hope I can save you some time with this plug-in. Feel free to contact me if you have any questions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMoolt%2FUnityRuntimePresets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMoolt%2FUnityRuntimePresets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMoolt%2FUnityRuntimePresets/lists"}