#Serializing and Deserializing Resources via Reflection

7 messages · Page 1 of 1 (latest)

frank finch
#

https://github.com/bevyengine/bevy/blob/main/examples/reflection/reflection.rs

I am building a library that allows users to leverage Bevy's reflection to save and load resources (among other things) at runtime.

Unfortunately, doing this requires that I erase type information for these Resources.

How would I insert a resource without knowing the underlying type? (insert_resource_by_id?)
How would I retrieve / serialize a resource without knowing the underlying type?
What would resources serialize into ? (Like DynamicComponent)

Any tips are appreciated.

GitHub

A refreshingly simple data-driven game engine built in Rust - bevy/reflection.rs at main · bevyengine/bevy

dusky sparrow
#

Just know that without FromReflect all your deserialized resources will likely be Dynamic*** (such as DynamicStruct). This means you can’t simply downcast to the full type or insert it directly. You’ll have to use Reflect::apply on an existing resource or use ReflectResource as seen in that PR

#

(the latter requires that your resource type is registered)

frank finch
#

Thanks. I am combining DynamicScene with a custom type registry to pull both Scene and resource information when saving. Now I am trying to figure out how to apply these dyn Reflect objects after retrieving them.