{"id":28564773,"url":"https://github.com/mminer/nonalloc-physics-wrapper","last_synced_at":"2026-05-18T02:03:02.927Z","repository":{"id":297865893,"uuid":"998143439","full_name":"mminer/nonalloc-physics-wrapper","owner":"mminer","description":"Wraps Unity's allocation-free physics functions.","archived":false,"fork":false,"pushed_at":"2025-06-09T15:44:02.000Z","size":8,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-08T20:25:20.263Z","etag":null,"topics":["game-dev","game-development","gamedev","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/mminer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-08T00:34:13.000Z","updated_at":"2025-10-07T20:51:07.000Z","dependencies_parsed_at":"2025-06-08T01:41:03.332Z","dependency_job_id":null,"html_url":"https://github.com/mminer/nonalloc-physics-wrapper","commit_stats":null,"previous_names":["mminer/non-alloc-physics-wrapper","mminer/nonalloc-physics-wrapper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/mminer/nonalloc-physics-wrapper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mminer%2Fnonalloc-physics-wrapper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mminer%2Fnonalloc-physics-wrapper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mminer%2Fnonalloc-physics-wrapper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mminer%2Fnonalloc-physics-wrapper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mminer","download_url":"https://codeload.github.com/mminer/nonalloc-physics-wrapper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mminer%2Fnonalloc-physics-wrapper/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33162446,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-17T22:39:12.733Z","status":"online","status_checked_at":"2026-05-18T02:00:06.436Z","response_time":71,"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-dev","game-development","gamedev","unity","unity3d"],"created_at":"2025-06-10T14:00:20.030Z","updated_at":"2026-05-18T02:03:02.910Z","avatar_url":"https://github.com/mminer.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# NonAlloc Physics Wrapper\n\nWraps the allocation-free versions of Unity's intersection functions —\n`Physics.RaycastNonAlloc`, `Physics.OverlapBoxNonAlloc`, and so forth — so that\nyou can avoid allocating and managing result arrays yourself.\n\n\n## Installation\n\nAdd the package to your project via\n[UPM](https://docs.unity3d.com/Manual/upm-ui.html) using the Git URL:\n\n```\nhttps://github.com/mminer/nonalloc-physics-wrapper.git\n```\n\n1. Open the Package Manager window in Unity (*Window \u003e Package Manager*)\n2. Click the \"+\" button in the top-left corner\n3. Select \"Install package from git URL...\"\n4. Enter the above Git URL\n5. Click \"Install\"\n\nAlternatively, add the following line to your `Packages/manifest.json` file:\n\n```json\n{\n  \"dependencies\": {\n    \"com.matthewminer.nonalloc-physics-wrapper\": \"https://github.com/mminer/nonalloc-physics-wrapper.git\",\n    // Other dependencies\n  }\n}\n```\n\nYou can also clone the repository and point UPM to your local copy.\n\n\n## Motivation\n\nUsing the `NonAlloc` physics functions reduces garbage collection overhead in\nyour game, particularly if you call them every frame. A typical implementation\nlooks like this:\n\n```csharp\nRaycastHit[] hits = new RaycastHit[10];\n\nvoid Update()\n{\n    var hitCount = Physics.RaycastNonAlloc(transform.position, transform.forward, hits);\n\n    for (var i = 0; i \u003c hitCount; i++)\n    {\n        var hit = hits[i];\n        Debug.Log(\"Hit: \" + hit.collider.name);\n    }\n}\n```\n\nThis is straightforward, but it requires you to manage an array of `RaycastHit`\nand exposes potential bugs if you misuse `hitCount`. A simpler option using this\npackage:\n\n```csharp\nvoid Update()\n{\n    var hits = NonAllocPhysics.RaycastAll(transform.position, transform.forward);\n\n    foreach (var hit in hits)\n    {\n        Debug.Log(\"Hit: \" + hit.collider.name);\n    }\n}\n```\n\nThe return type is\n[`ReadOnlySpan`](https://learn.microsoft.com/en-us/dotnet/api/system.readonlyspan-1),\na lightweight container that allows you to iterate over the raycast hits in a\nforeach loop. The signature of `NonAllocPhysics.RaycastAll` resembles\n`Physics.RaycastAll`, but produces no memory allocations. The underlying results\nbuffer is reused across calls.\n\n\n## Usage\n\nAny time you use a `Physics` intersection function, prefix it with `NonAlloc`\nand iterate over the return value as before.\n\n```diff\n- var hits = Physics.RaycastAll(ray);\n+ var hits = NonAllocPhysics.RaycastAll(ray);\n\n- var colliders = Physics.OverlapBox(center, halfExtents);\n+ var colliders = NonAllocPhysics.OverlapBox(center, halfExtents);\n\n... and so on.\n```\n\n### Results Buffer Size\n\nHow large the internal results buffer needs to be depends on your game's\nspecific needs. The default size is 64, but increase or decrease this as needed.\n\n```csharp\nNonAllocPhysics.resultsBufferSize = 100;\n```\n\n### Warning Logs\n\nBy default, `NonAllocPhysics` logs a warning to the console if the results\nbuffer is too small to hold all the results, in which case you may want to\nincrease the buffer size. It does so only when your game is running in the\neditor.\n\nTo customize this behaviour, either to disable the warnings entirely or to log\nwarnings in builds, set `NonAllocPhysics.logger`.\n\n```csharp\n// Never log warnings.\nNonAllocPhysics.logger = null;\n\n// Always log warnings, even in builds.\nNonAllocPhysics.logger = Debug.unityLogger;\n```\n\n\n## API\n\nAll function signatures match their `Physics` and `Physics2D` counterparts.\n\n```csharp\nNonAllocPhysics.BoxCastAll\nNonAllocPhysics.CapsuleCastAll\nNonAllocPhysics.OverlapBox\nNonAllocPhysics.OverlapCapsule\nNonAllocPhysics.OverlapSphere\nNonAllocPhysics.RaycastAll\nNonAllocPhysics.SphereCastAll\nNonAllocPhysics2D.GetRayIntersectionAll\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmminer%2Fnonalloc-physics-wrapper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmminer%2Fnonalloc-physics-wrapper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmminer%2Fnonalloc-physics-wrapper/lists"}