{"id":15137913,"url":"https://github.com/robertdodd/bevy_reflect_utils","last_synced_at":"2025-10-23T13:30:54.695Z","repository":{"id":245774425,"uuid":"819192319","full_name":"robertdodd/bevy_reflect_utils","owner":"robertdodd","description":"A small, plugin-less utility library making it easier to work with reflection in bevy.","archived":false,"fork":false,"pushed_at":"2024-07-05T05:21:20.000Z","size":107,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-30T18:48:22.607Z","etag":null,"topics":["bevy","bevy-engine","game-development","gamedev","gui","ui"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robertdodd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","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}},"created_at":"2024-06-24T02:47:37.000Z","updated_at":"2024-08-28T00:00:53.000Z","dependencies_parsed_at":"2024-06-28T05:31:07.134Z","dependency_job_id":null,"html_url":"https://github.com/robertdodd/bevy_reflect_utils","commit_stats":null,"previous_names":["robertdodd/bevy_reflect_utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdodd%2Fbevy_reflect_utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdodd%2Fbevy_reflect_utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdodd%2Fbevy_reflect_utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robertdodd%2Fbevy_reflect_utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robertdodd","download_url":"https://codeload.github.com/robertdodd/bevy_reflect_utils/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237834646,"owners_count":19373763,"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":["bevy","bevy-engine","game-development","gamedev","gui","ui"],"created_at":"2024-09-26T07:03:32.695Z","updated_at":"2025-10-23T13:30:54.689Z","avatar_url":"https://github.com/robertdodd.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bevy Reflect Utils\n\nA small, plugin-less utility library making it easier to work with reflection\nin [bevy](https://bevyengine.org/).\n\n---\n\n## Development\n\n\u003e [!WARNING]\n\u003e UNDER DEVELOPMENT, EXPECT BREAKING CHANGES\n\n## Motivation\n\nThis library was written to build re-usable UI widgets.\n\nReflection code is usually very verbose and hard to follow. The functions in this library only require a `ReflectTarget`\npointing to a field and an `\u0026mut World`, and return an easy-to-handle `Result\u003cT, ReflectError\u003e`.\n\n## Simple Example\n\n```rust\nuse bevy::prelude::*;\nuse bevy_reflect_utils::*;\n\nfn main() {\n    App::new()\n        .add_plugins(DefaultPlugins)\n        .init_resource::\u003cExampleResource\u003e()\n        .add_systems(Startup, setup)\n        // IMPORTANT: The types you want to operate on must be registered\n        .register_type::\u003cExampleResource\u003e()\n        .run();\n}\n\n// IMPORTANT: The types you operate on must derive `Reflect`\n#[derive(Resource, Reflect, Debug, Default)]\n#[reflect(Resource, Default, Debug)]\npub struct ExampleResource {\n    value: bool,\n}\n\nfn setup(world: \u0026mut World) {\n    // Define a `ReflectTarget` pointing to `ExampleResource::value`\n    let target = ReflectTarget::new_resource::\u003cExampleResource\u003e(\"value\");\n\n    // Read the initial value\n    let initial_value = target.read_value::\u003cbool\u003e(world).unwrap();\n    println!(\"initial value: {}\", initial_value);\n\n    // Set a new value\n    target.set_value(world, !initial_value).unwrap();\n\n    // Read the new value\n    let new_value = target.read_value::\u003cbool\u003e(world).unwrap();\n    println!(\"new value: {}\", new_value);\n}\n```\n\nThis example will print the following:\n\n```\ninitial value: false\nnew value: true\n```\n\nYou can run this same example with:\n\n```shell\ncargo run --example simple\n```\n\n## Recommended Usage\n\nUse `Commands` to perform reflection when possible. Use exclusive systems\nwhen you can't avoid it.\n\nFor example, to update a value when a button is clicked:\n\n```rust\nfn handle_click_events(mut commands: \u0026mut Commands) {\n    // if button was clicked...\n    let target = ReflectTarget::new_resource::\u003cExampleResource\u003e(\"value\");\n    commands.queue(move |world: \u0026mut World| {\n        match target.set_value(world, true) {\n            Ok(ReflectSetSuccess::Changed) =\u003e info!(\"Success\"),\n            Ok(ReflectSetSuccess::NoChanges) =\u003e warn!(\"Value not changed\"),\n            Err(err) =\u003e error!(\"{err:?}\"),\n        }\n    });\n}\n```\n\n## `ReflectTarget` Target Types\n\nCreate a `ReflectTarget` referencing a field on an `Entity` and `Component`:\n\n```rust\nlet target = ReflectTarget::new_component::\u003cExampleComponent\u003e(entity, \"value\");\n```\n\nCreate a `ReflectTarget` referencing a field on a `Resource`:\n\n```rust\nlet target = ReflectTarget::new_resource::\u003cExampleResource\u003e(\"value\");\n```\n\n## `ReflectTarget` Operations\n\n`ReflectTarget` provides the following operations:\n\n### Read Value\n\n\u003e Requires knowing the underlying type.\n\n```rust\ntarget.read_value::\u003cf32\u003e(world);\n```\n\nReturn Value:\n\n```rust\nResult\u003cf32, ReflectError\u003e\n```\n\n### Set Value\n\n\u003e Requires knowing the underlying type.\n\n```rust\ntarget.set_value(world, 0.5);\n```\n\nReturn Value:\n\n```rust\nResult\u003cReflectSetSuccess, ReflectError\u003e\n```\n\n### Toggle Between Enum Variant\n\nToggle between the previous/next enum variants.\n\nAlso works with data variants, provided the variant implements and reflects `Default`.\n\n\u003e Does not require knowing the underlying type.\u003cbr /\u003e\n\u003e **Important:** Does not wrap around when reaching the beginning or end of\n\u003e the list of variants.\n\n```rust\ntarget.toggle_enum_variant(world, EnumDirection::Forward);\ntarget.toggle_enum_variant(world, EnumDirection::Backward);\n```\n\nReturn Value:\n\n```rust\nResult\u003cReflectSetSuccess, ReflectError\u003e\n```\n\n### Read Enum Variant Name\n\n\u003e Does not require knowing the underlying type.\n\n```rust\ntarget.read_enum_variant_name(world);\n```\n\nReturn Value:\n\n```rust\nResult\u003cString, ReflectError\u003e\n```\n\n### Read Serialized Value\n\n\u003e Does not require knowing the underlying type.\n\n```rust\ntarget.read_value_serialized(world);\n```\n\nReturn Value:\n\n```rust\nResult\u003cString, ReflectError\u003e\n```\n\nExample:\n\n```rust\nOk(\"{\\\"f32\\\":0.5}\")\n```\n\n### Set Serialized Value\n\n\u003e Does not require knowing the underlying type.\n\n```rust\ntarget.set_value_serialized(world, \"{\\\"f32\\\":0.5}\".to_string());\n```\n\nReturn Value:\n\n```rust\nResult\u003cReflectSetSuccess, ReflectError\u003e\n```\n\n### Partial Equality Against a Serialized Value\n\n\u003e Does not require knowing the underlying type.\n\n```rust\ntarget.partial_eq_serialized(world, \"{\\\"f32\\\":0.5}\".to_string());\n```\n\nReturn Value:\n\n```rust\nResult\u003cbool, ReflectError\u003e\n```\n\n## Errors\n\nThe primary error type is [`ReflectError`](https://github.com/robertdodd/bevy_reflect_utils/blob/master/src/errors.rs).\n\n## Set Value Return Type\n\nMost operations that set a value have the following return type:\n\n```rust\nResult\u003cReflectSetSuccess, ReflectError\u003e\n```\n\nWhere [`ReflectSetSuccess`](https://github.com/robertdodd/bevy_reflect_utils/blob/master/src/errors.rs)\nallows you know whether the field was changed by the operation:\n\n```rust\npub enum ReflectSetSuccess {\n    Changed,\n    NoChanges,\n}\n```\n\n## Compatible Bevy versions\n\n| `bevy_reflect_utils` | `bevy` |\n|:---------------------|:-------|\n| `0.4`                | `0.16` |\n| `0.3`                | `0.15` |\n| `0.2`                | `0.14` |\n| `0.1`                | `0.13` |\n\n## License\n\nDual-licensed under either of\n\n- Apache License, Version 2.0,\n  ([LICENSE-APACHE](https://github.com/robertdodd/bevy_round_ui/blob/master/LICENSE-APACHE) or\n  https://www.apache.org/licenses/LICENSE-2.0)\n- MIT license ([LICENSE-MIT](https://github.com/robertdodd/bevy_round_ui/blob/master/LICENSE-MIT) or\n  https://opensource.org/licenses/MIT)\n\nat your option.\n\n## Contribution\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as\ndefined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdodd%2Fbevy_reflect_utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobertdodd%2Fbevy_reflect_utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobertdodd%2Fbevy_reflect_utils/lists"}