Skip to content
crates · rust · bevy · ffi · unity

Bevy game-logic crates to Unity viauniti

A Rust cdylib that exposes the KBVE Bevy game-logic crates — pathfinder, inventory, battle, skills — to the Unity runtime used by RareIcon, through generated csbindgen C# bindings.

Four crates in one dylib

uniti compiles as a cdylib and is loaded by Unity as a native plugin, bundling the KBVE Bevy game-logic crates plus two runtime helpers so Unity needs nothing on the host.

  • Logic — bevy_pathfinder, bevy_inventory, bevy_battle, bevy_skills.
  • Helpers — bundled rusqlite + pure-Rust zstd.
Rust cdylibCrate
csbindgen C#Bindings
UnityConsumer
MITLicense

What it gives you

Features

Bundles game-logic crates

Bundles bevy_pathfinder, bevy_inventory, bevy_battle, and bevy_skills into a single native plugin.

Generated C# bindings

build.rs invokes csbindgen at build time to write the C# wrapper Uniti.g.cs into the Unity project.

No host dependencies

Statically bundles rusqlite (bundled feature) and pure-Rust zstd, so Unity loads the dylib without host libraries.

Per-platform Nx builds

Nx targets build the release cdylib and copy it into the Unity Plugins tree for macOS, Windows, and Linux.

The bridge

Overview

uniti is the C FFI bridge that exposes the KBVE Bevy game-logic crates to the Unity runtime used by RareIcon. It compiles as a cdylib and is loaded by Unity as a native plugin.

Bindings on the C# side are generated by csbindgen at build time and committed to the Unity project as Uniti.g.cs.

Crates & build

Bundled crates, build & bindings

CratePurpose
bevy_pathfinderGrid flow-field navigation + chokepoint detection
bevy_inventoryItem / slot persistence
bevy_battleCombat resolution
bevy_skillsSkill / proc tables

Plus two runtime helpers compiled into the dylib so Unity does not need them on the host:

  • rusqlite with the bundled feature — save-archive persistence, no system libsqlite3 dep.
  • zstd with default features disabled — pure-Rust compression for save blobs.

Each Nx target builds the release cdylib and copies it into the Unity Plugins/ tree for the matching platform.

Terminal window
npx nx run uniti:build:macos
npx nx run uniti:build:windows
npx nx run uniti:build:linux
npx nx run uniti:build:all

On macOS the target also runs xattr -cr and an adhoc codesign --force --deep --sign - so the dylib loads through Gatekeeper without a quarantine prompt.

build.rs invokes csbindgen and writes the C# wrapper to:

apps/rareicon/unity-rareicon/Assets/_RareIcon/Scripts/Native/Uniti.g.cs

Hand-written wrapper classes live alongside it under Native/Wrappers/ (for example NativeWorld).

Tracked in the dispatch manifest under the crates pipeline. The standard test / lint nx targets are wired:

Terminal window
npx nx run uniti:test
npx nx run uniti:lint

MIT

Questions

Frequently asked

What is the uniti crate?

uniti is the C FFI bridge that exposes the KBVE Bevy game-logic crates to the Unity runtime used by RareIcon. It compiles as a cdylib and is loaded by Unity as a native plugin, bundling bevy_pathfinder, bevy_inventory, bevy_battle, and bevy_skills.

How are the C# bindings generated?

build.rs invokes csbindgen at build time to generate a C# wrapper (Uniti.g.cs) that is committed into the Unity project under Assets/_RareIcon/Scripts/Native. Hand-written wrapper classes such as NativeWorld live alongside it under Native/Wrappers.

Does uniti need system libraries on the host?

No. It statically bundles rusqlite with the bundled feature (so no system libsqlite3 is required) and zstd with default features disabled for pure-Rust save-blob compression, so Unity can load the dylib without host dependencies.