#Passing constants/variables in bevy system

19 messages · Page 1 of 1 (latest)

trail monolith
#

I am having trouble passing a variable into a bevy system. Specifically it is the send(tx) half of an mpsc channel. I thought the Local<> parameter would help, but I can’t find the proper syntax.

Trying to pass:

let tx = mpsc::channel();

into a system . Anyone have any ideas or experience with this?

past gyro
#

Where are you getting the mpsc::channel()?

#

you could capture it in a closure when you register the system, otherwise if its a static function like fn my_system() { } then you'd need to make it a resource or something else so it could find it

trail monolith
#

I import it with a use statement and then I’m calling it at the top of main.

#

So if I stuck it in a struct I could pass it in?

past gyro
#

I mean just insert it as a resource

#

and have the system fetch that resource

trail monolith
#

Ah. So .insert_reaource(tx)

#

That’s sufficient?

#

Sorry for these noob questions.

past gyro
#

no problem, yeah, you might want to wrap it with a MyChannel to avoid conflicting with types in the future

trail monolith
#

I’m going to try that. I’m getting trait bound errors left and right when I try to pass in tx as a Local

olive acorn
#

in the standard library, I believe mpsc tx is not sync, but is copyable

#

*clonable

#

So you would need to use a non send resource -

#

Or you could wrap it in an Arc, and then use that as a resource

#

Actually - there is another option... You could wrap it in a type that implements either FromWorld or Default, since Local only requires Send... But for that you need a way to grab the channel tx from the world the first time the system is called.

trail monolith