{"id":13661535,"url":"https://github.com/lumpn/unity-scheduling","last_synced_at":"2026-04-04T22:48:17.406Z","repository":{"id":80725165,"uuid":"206922677","full_name":"lumpn/unity-scheduling","owner":"lumpn","description":"Non-allocating Invoke/InvokeRepeating scheduling facilities for Unity","archived":false,"fork":false,"pushed_at":"2021-09-20T07:20:18.000Z","size":105,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-08-02T05:13:15.505Z","etag":null,"topics":["scheduler","scheduling","tasks","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/lumpn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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":"2019-09-07T05:52:58.000Z","updated_at":"2023-03-09T18:00:01.000Z","dependencies_parsed_at":"2023-06-29T20:45:14.203Z","dependency_job_id":null,"html_url":"https://github.com/lumpn/unity-scheduling","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/lumpn%2Funity-scheduling","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumpn%2Funity-scheduling/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumpn%2Funity-scheduling/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lumpn%2Funity-scheduling/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lumpn","download_url":"https://codeload.github.com/lumpn/unity-scheduling/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223979418,"owners_count":17235395,"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":["scheduler","scheduling","tasks","unity3d"],"created_at":"2024-08-02T05:01:36.602Z","updated_at":"2026-04-04T22:48:17.368Z","avatar_url":"https://github.com/lumpn.png","language":"C#","funding_links":[],"categories":["C\\#"],"sub_categories":[],"readme":"# unity-scheduling\nA non-allocating Invoke/InvokeRepeating scheduler for Unity\n\n## Installation\nDownload the entire repository from https://github.com/lumpn/unity-scheduling and use Unity's built in package manager to [add package from disk](https://docs.unity3d.com/Manual/upm-ui-local.html).\n\n## Usage\n```csharp\nvoid CastFireball()\n{\n    scheduler.InvokeRepeating(ApplyFireDamageOverTime, castDelay, repeatInterval, this, enemy);\n}\n\nstatic void ApplyDamage(object owner, object state)\n{\n    var wizard = (Wizard)owner;\n    var enemy = (Enemy)state;\n\n    var damage = DamageSystem.CalculateFireDamage(wizard);\n    enemy.TakeDamage(damage);\n}\n```\n\n### Static method\n```csharp\nclass Wizard\n{\n    void CastSpell()\n    {\n        scheduler.Invoke(ApplyDamage, castDelay);\n    }\n\n    static void ApplyDamage(object owner, object state)\n    {\n        // apply damage here\n    }\n}\n```\n\n### Member method\n```csharp\nclass Wizard\n{\n    void CastSpell()\n    {\n        scheduler.Invoke(ApplyDamage, castDelay, this);\n    }\n\n    // NOTE: we are using a static method to avoid temporarily\n    // allocating memory for a closure over the `this` reference.\n    static void ApplyDamage(object owner, object state)\n    {\n        var wizard = (Wizard)owner;\n        wizard.ApplyDamage();\n    }\n    \n    void ApplyDamage()\n    {\n        // apply damage here\n    }\n}\n```\n\n### Passing state\n```csharp\nclass Wizard\n{\n    void CastSpell()\n    {\n        scheduler.Invoke(ApplyDamage, castDelay, this, targetEnemy);\n    }\n\n    static void ApplyDamage(object owner, object state)\n    {\n        var wizard = (Wizard)owner;\n        var ememy = (Enemy)state;\n        wizard.ApplyDamage(state);\n    }\n    \n    void ApplyDamage(Enemy enemy)\n    {\n        // apply damage to enemy here\n    }\n}\n```\n\n### Cancellation token\n```csharp\nclass Wizard\n{\n    private ICancellationToken castToken;\n\n    void CastSpell()\n    {\n        castToken = new CancellationToken();\n        scheduler.Invoke(ApplyDamage, castDelay, this, targetEnemy, castToken);\n    }\n    \n    void CancelCast()\n    {\n        castToken.Cancel();\n    }\n    \n    // NOTE: will never get called if the token gets\n    // cancelled before the cast delay is over.\n    static void ApplyDamage(object owner, object state)\n    {\n        // ...\n    }\n}\n```\n\n### InvokeRepeating\n```csharp\nclass Wizard\n{\n    void CastSpell()\n    {\n        scheduler.InvokeRepeating(ApplyDamage, castDelay, repeatInterval, this, targetEnemy);\n    }\n    \n    static void ApplyDamage(object owner, object state)\n    {\n        // ...\n    }\n}\n```\n\n## Notes\n* For convencience, create a singleton scheduler. See `SchedulerHost` for details.\n* Schedulers should get updated every frame. See `SchedulerHost` for details.\n* The invoked method should be `static` to avoid capturing the `this` reference, which would generate garbage.\n* For non-static methods, add a `static` method and pass `this` via the `owner` parameter.\n  Unfortunately this kind of boilerplate is the only way to avoid generating garbage.\n* Optionally additional state can be passed via the `state` parameter.\n* See `InvokeDemo` for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flumpn%2Funity-scheduling","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flumpn%2Funity-scheduling","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flumpn%2Funity-scheduling/lists"}