{"id":13663566,"url":"https://github.com/rfadeev/unity-forge-anim-callbacks","last_synced_at":"2026-03-05T20:48:18.988Z","repository":{"id":45143272,"uuid":"118001753","full_name":"rfadeev/unity-forge-anim-callbacks","owner":"rfadeev","description":"Runtime callbacks for Unity animation clips used in Animator and Animation components.","archived":false,"fork":false,"pushed_at":"2020-01-28T12:46:19.000Z","size":67,"stargazers_count":44,"open_issues_count":0,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-14T07:48:52.793Z","etag":null,"topics":["c-sharp","unity","unity-animation-events"],"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/rfadeev.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}},"created_at":"2018-01-18T15:36:03.000Z","updated_at":"2024-09-05T12:11:06.000Z","dependencies_parsed_at":"2022-07-13T16:45:04.050Z","dependency_job_id":null,"html_url":"https://github.com/rfadeev/unity-forge-anim-callbacks","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfadeev%2Funity-forge-anim-callbacks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfadeev%2Funity-forge-anim-callbacks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfadeev%2Funity-forge-anim-callbacks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rfadeev%2Funity-forge-anim-callbacks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rfadeev","download_url":"https://codeload.github.com/rfadeev/unity-forge-anim-callbacks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221820794,"owners_count":16886225,"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":["c-sharp","unity","unity-animation-events"],"created_at":"2024-08-02T05:02:30.920Z","updated_at":"2025-10-28T16:50:57.385Z","avatar_url":"https://github.com/rfadeev.png","language":"C#","readme":"[![license](https://img.shields.io/github/license/rfadeev/unity-forge-anim-callbacks.svg)](https://github.com/rfadeev/unity-forge-anim-callbacks/blob/master/LICENSE.md)\n[![openupm](https://img.shields.io/npm/v/com.rfadeev.unityforge.animcallbacks?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.rfadeev.unityforge.animcallbacks/)\n\n# Unity Forge Anim Callbacks\nRuntime callbacks for Unity animation clips used in Animator and Animation components.\n\n## Motivation\nWhile Unity animation events provide ability to call method from specific time point of animation clip, there is no Unity API for binding such method at runtime from code. So it was decided to implement such way to add callbacks to Unity animation clips.\n\n## Installation\n\n### Install via OpenUPM\n\nThe package is available on the [openupm registry](https://openupm.com). It's recommended to install it via [openupm-cli](https://github.com/openupm/openupm-cli).\n\n```\nopenupm add com.rfadeev.unityforge.animcallbacks\n```\n\n### Install via Git\n\nProject supports Unity Package Manager. To install project as Git package do following:\n1. Close Unity project and open the `Packages/manifest.json` file.\n2. Update `dependencies` to have `com.rfadeev.unityforge.animcallbacks` package:\n```json\n{\n  \"dependencies\": {\n    \"com.rfadeev.unityforge.animcallbacks\": \"https://github.com/rfadeev/unity-forge-anim-callbacks.git#upm\"\n  }\n}\n```\n3. Open Unity project.\n\nAlternatively, using upm branch add this repository as submodule under `Assets` folder or download it and put to `Assets` folder of your Unity project. \n\n## Usage\nImport `UnityForge.AnimCallbacks` namespace to be able to use extensions for callbacks. Both Animator and Animation extension methods have same names:\n* `AddClipStartCallback` - to add callback for start of animation clip.\n* `AddClipEndCallback` - to add callback for end of animation clip.\n* `AddClipCallback` - to add callback for given timeline position of animation clip.\n* `RemoveClipStartCallback` - to remove callback for start of animation clip.\n* `RemoveClipEndCallback` - to remove callback for end of animation clip.\n* `RemoveClipCallback` - to remove callback for given timeline position of animation clip.\n\nSeveral callbacks can be added at the same position of animation clip timeline. Callbacks are called in order they were added.\nNote that if using anonymous functions, you need to store delegate instance for correct removal of callback via `RemoveClip*` methods.\n\n### Animator\nFor Animator's animation clip callbacks layer index and clip name are required to add callback. To add callback at given timeline position, position parameter representing time in seconds from clip start is required.\n```csharp\nvar animator = GetComponent\u003cAnimator\u003e();\nvar layerIndex = 0;\nvar clipName = \"AnimatorClipName\";\n\nanimator.AddClipStartCallback(layerIndex, clipName, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": started\", clipName);\n});\nanimator.AddClipEndCallback(layerIndex, clipName, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": ended\", clipName);\n});\nanimator.AddClipCallback(layerIndex, clipName, 0.5f, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": callback at 0.5f seconds after start\", clipName);\n});\n```\n\nTo remove callback same parameters are required as in complementary add callback method.\n```csharp\nprivate void AddExampleCallback()\n{\n    animator.AddClipStartCallback(layerIndex, clipName, LogStart);\n}\n\nprivate void RemoveExampleCallback()\n{\n    animator.RemoveClipStartCallback(layerIndex, clipName, LogStart);\n}\n\nprivate void LogStart()\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": started\", clipName);\n}\n```\n\nFind more Animator examples [here](https://github.com/rfadeev/unity-forge-anim-callbacks/tree/master/Packages/com.rfadeev.unityforge.animcallbacks/Samples/Animator).\n\n### Animation\nFor Animation's animation clip callbacks clip name is required to add callback. To add callback at given timeline position, position parameter representing time in seconds from clip start is required.\n```csharp\nvar animation = GetComponent\u003cAnimation\u003e();\nvar clipName = \"AnimationClipName\";\n\nanimation.AddClipStartCallback(clipName, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": started\", clipName);\n});\nanimation.AddClipEndCallback(clipName, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": ended\", clipName);\n});\nanimation.AddClipCallback(clipName, 0.5f, () =\u003e\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": callback at 0.5f seconds after start\", clipName);\n});\n```\n\nTo remove callback same parameters are required as in complementary add callback method.\n```csharp\nprivate void AddExampleCallback()\n{\n    animation.AddClipStartCallback(clipName, LogStart);\n}\n\nprivate void RemoveExampleCallback()\n{\n    animation.RemoveClipStartCallback(clipName, LogStart);\n}\n\nprivate void LogStart()\n{\n    Debug.LogFormat(\"Clip \\\"{0}\\\": started\", clipName);\n}\n```\n\nFind more Animation examples [here](https://github.com/rfadeev/unity-forge-anim-callbacks/tree/master/Packages/com.rfadeev.unityforge.animcallbacks/Samples/Animation).\n\n## Caveats\nCallbacks are implemented via adding Unity animation events to the animation clip and `AnimationEventReceiver` component to the same object Animator or Animation is attached. Following should be taken into account when using callbacks:\n* Since Unity animation event calls all components which have method with the name from animation event, attaching component which has method named `OnTimelineEventRaised` on the same object which adds callback at runtime, can have undesired consequences since these component's method will be called.\n* Using `AnimationEventReceiver` directly (in editor or from user code) can result in not desired calls if callbacks are populated from user code or if `OnTimelineEventRaised` method is used in animation event added directly (in editor or from user code).\n* Runtime representation of `AnimationClip` is persistent while application is running. So if callback is added, but not removed, coressponding animation event will be present in animation clip even if Animation or Animator component is destroyed.\n* Negative animator state speed does not trigger start and end animation events hence no callbacks are called.\n","funding_links":[],"categories":["C\\#","Script Utility"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfadeev%2Funity-forge-anim-callbacks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frfadeev%2Funity-forge-anim-callbacks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frfadeev%2Funity-forge-anim-callbacks/lists"}