1

I'm trying to update an object position stream by combining the speed stream with it and publishing the new position in that position stream, I'm doing this by subscribing to the combined stream in Start():

Observable.CombineLatest(position_stream, speed_stream, (position, speed) =>
    {
        return position + speed;
    }).Subscribe(a => new_position = a);

and publishing the new position in Update():

position_stream.OnNext(new_position);

is this approach compatible with reactive programming paradigm or it's abusing rx operators with an imperative mindset? if so can someone help me to find the right way it should be done.

Mahsa
  • 41
  • 9
  • Updating an observable in Update() method seems a bit weird. Rx is more about avoiding Update() at all. It is more for reacting to some events once in a while. Can you provide more complete description about what are you trying to achieve? – kolodi Apr 06 '21 at 17:18
  • @kolodi thanks for your reply. i want to change my gameobject position based on 2 streams : it's position and speed, in each frame i want the speed to be added to current position and make the next position. i'm trying to find out what's the correct way to do so. – Mahsa Apr 08 '21 at 14:55
  • if you need to use Update() method and manipulate the same object, I can see no practical usage of Rx stream here. There could be some reason if you maybe make the stream outside and make so many objects can update/subscribe to it so you can have some reactivness for that matter. For your specific use-case you do not add any value when using streams, in Update method you can write all the business logic right away. Also, I never used streams or reactive properties that are updated every frame, Rx is more about event-driven architecture rather than game loop based one. – kolodi Apr 09 '21 at 12:12

0 Answers0