Adding Event Channels to Pong Tutorial


ECS still puzzles me. In Pong tutorial, Systems are something added to the game in the main function, and are not added nor removed at runtime.

I was following this: to add a Producer system and a Receiver system.

Problem is: in the example the Receiver’s new method is called upon an instance of the World object. I do not have that instance when in the main function. How can I make it work?

(Abovegame) #2

You need to implement the SystemDesc on your system. This way you get the world in the build method.

1 Like

I used the #[derive(SystemDesc)], not sure I’ve understood what it does. The problem is that in the example the World is passed as a parameter to the new, so in theory it should be passed from the main, which I think it is not possible. Can you provide me another code example from to the one in the Book? I think it is either wrong or incomplete.

(Abovegame) #4

Well basically you manually implement the SystemDesc trait, for the system you can just have:

impl MySystem {
    pub fn new(reader: ReaderId) -> Self {
        Self { reader } 

In your build method of the SystemDesc trait you create a ReaderId from the specified event channel.


Thank you very much for helping! Unfortunately, I still do not get it working.

I still think the tutorial/book is kinda wrong in that part because I can get Pong running by basically copy-paste the code, while with this Event Channel paragraph it just doesn’t seem to work out of the box.

If I implement SystemDesc instead of just deriving it, things are getting even more complex to me that I am both a newbie to Rust and to Amethyst. In your example, MySystem::new needs a ReaderId to be passed on, I guess the idea is to give it through the build method, but my understanding is that you first call new() normally and then eventually other methods, so in the main() function I still have no clue how to build MySystem and pass it to the GameDataBuilder.

I learnt that the creation of systems can be deferred, that I think is where the build() method comes into play. But I still need to create it first with new() I guess, and maybe ReaderId needs to be Option<ReaderId> and until build() is called is None… but I am not sure.

Again thanks for helping, looking forward to any answer/hint about it