Best practice for storing state in a Plugin #6352
-
Hi all 👋 I'm fairly new to both Bevy and Rust, so I hope this isn't too dumb of a question, but I'm having trouble grokking how to store state data in a Plugin I'm working on. I'm trying to figure out how to keep a long-lived input hashmap in my input handler Plugin so as to support click and drag functionality. I've defined the Plugin as follows and imported it into my main App.
The above works fine and dandy, but when I change it to
I start getting the following warning in VSCode
Clicking through various examples, it seems like all Plugins I can find use unit structs. So I'm assuming the above error might have something to do with me adding fields. My question is, if that's true, where should I keep the I seem to have gotten my desired behavior working by moving the data to a Resource struct (as follows), but I'm pretty unsure of whether that's appropriate usage of Bevy/Resources.
Thanks in advance for any guidance y'all can offer! 😄 |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
Yes, using resources is the intended pattern here :) Plugin state information is best used just to configure setup. |
Beta Was this translation helpful? Give feedback.
-
Cool, I think that makes sense, it seems like it's actually pretty easy to get the Resource into whichever Systems need it 😄 . Thanks @alice-i-cecile! |
Beta Was this translation helpful? Give feedback.
Yes, using resources is the intended pattern here :) Plugin state information is best used just to configure setup.