close
The Wayback Machine - https://web.archive.org/web/20210422181503/https://gitter.im/neuecc/UniRx

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
  • Image
Activity
    Image
    sd
    @sdebaun
    er inside the sprite controller monobehavior
    theres a very obvious difference
    the default unity way, the sprite instantly stops when i take my finger off the key
    i boiled it down to the basic
    public class InputObservable : MonoBehaviour
    {
        public ISubject<Vector2> axis_ = new Subject<Vector2>();
    
        public void Update()
        {
            var next = new Vector2(
                    Input.GetAxis("Horizontal"),
                    Input.GetAxis("Vertical")
                ).normalized;
            Debug.Log(next);
    
            axis_.OnNext(next);
        }
    
    }
    but i also experimented with some of the fancy UniRx magic that i totally understand, different versions where i use
    this kind of stuff
            //axis_ = axis_.SubscribeOnMainThread().ObserveOnMainThread();
            //var interval = Observable.IntervalFrame(1);
            ////var interval = Observable.EveryUpdate();
            ////var interval = Observable.EveryFixedUpdate();
            ////var interval = Observable.ThrottleFrame(1);
    Image
    sd
    @sdebaun
    i dont understand enough about the internals of unirx to figure out why this happens, anyone have any ideas of where to look?
    using unity package version of unirx btw
    Image
    sd
    @sdebaun
    image.png
    interesting. theres something definitely involved in the order in which the subject emits, and the observer gets the new value, and when rigidbody physics is happening
    starting from line 6 from the bottom - that InputObservable debuglog happens right after the subject's OnNext is called
    Update and FixedUpdate are just showing the velocity of the rigidbody object
    UpdateInputAxis is the subscriber to the subject
    Image
    sd
    @sdebaun
    omg
    fuck me
    the snappy version was using GetAxisRaw
    the native version was using GetAxisRaw, the observable version was using GetAxis
    asldkjfalsdkfjal;titase
    GetAxis smooths
    imma go beat myself to death with a wet noodle bbl
    Image
    Jean-Marc Primeau
    @jmprimeau

    Hi all, is this the correct behaviour for SelectMany?

    var A = new ReactiveProperty<int>(10);
    var B = new ReactiveProperty<int>(20);
    var V = new ReactiveProperty<ReactiveProperty<int>>(A);
    
    var Vsm = V.SelectMany(_ => _).ToReadOnlyReactiveProperty();
    
    Assert.AreEqual(10, Vsm.Value, "Flattened value initialized to A's value == 10");
    
    A.Value = 11;
    Assert.AreEqual(11, Vsm.Value, "Value change in initial value should be reflected in flattened value");
    
    V.Value = B;
    Assert.AreEqual(20, Vsm.Value, "New flattened value should be reflected");
    
    B.Value = 21;
    Assert.AreEqual(21, Vsm.Value, "So far so good");
    
    A.Value = 1024;
    Assert.AreNotEqual(1024, Vsm.Value, "We should no longer be listening to A");

    This isn't better...

          var A = new Subject<int>();
          var B = new Subject<int>();
          var V = new Subject<IObservable<int>>();
    
          var Vsm = V.SelectMany(_ => _);
          var VsmLatest = 0;
    
          Vsm.Subscribe(v => VsmLatest = v);
    
          Assert.AreEqual(0, VsmLatest);
    
          V.OnNext(A);
          Assert.AreEqual(0, VsmLatest);
    
          A.OnNext(10);
          Assert.AreEqual(10, VsmLatest);
    
          A.OnNext(11);
          Assert.AreEqual(11, VsmLatest);
    
          B.OnNext(20);
          V.OnNext(B);
          Assert.AreEqual(11, VsmLatest);
    
          B.OnNext(21);
          Assert.AreEqual(21, VsmLatest);
    
          A.OnNext(1024);
          Assert.AreNotEqual(1024, VsmLatest, "We should no longer be listening to A");
    Basically, once the value of V changes to another observable, SelectMany should Dispose of the subscription it had on the previous observable; this doesn't seem to be the case.
    Bonus question: Shouldn't the result of SelectMany be Disposable in any case as there seems to be a buried subscription in there?
    Image
    Martin Gonzalez
    @MartinGonzalez
    Question, is there a way to use Wait() in MainThread?
    Image
    krisrok
    @krisrok
    hey guys. i'm fining myself coming back to unirx every few months or so. what i really miss are some tutorials or write-ups going in more detail in how a full fletched rx project is set up. i've read enough about click-counters and simple ui bindings. i need the good stuff! ;) is there anything out there?
    Image
    Mirko Jugurdzija
    @biotech77
    hi guys, i am trying to upgrade project to unity 2020 and it fails with unirx, what version to use and what to do to make errors disappear? thanks!
    Image
    Szymon Gatner
    @slimshader
    @biotech77 I am using UniRx in 2020.2 beta with no problems
    Image
    Bastien Guyl
    @bguyl
    Hi there :wave:
    I was using MainThreadDispatcher.Post with an older version, I updated UniRx and now I see there is a n additionnal state argument. Is it required ?
    What it's purpose ?
    Image
    chadobado
    @chadobado
    Hey quick question - can anyone comment on the performance of ReactiveProperty and UniRX generally? I'm looking at using UniRX to handle networked streams of blendshape data (collection of 53 structs for each blendshape with int index and float coefficient). With 8 connected clients (each streaming their own blendshapes multiple times/second) it's a lot of data to push. Just want to make sure UniRX is suitable for this requirement. Thanks in advance
    Image
    Andrei Müller (Andy Miira)
    @andreiagmu
    Hi! Is this a support community for UniTask (v2) also? I started using UniTask on my Unity project (without UniRx), and I have a question about it
    I want to use the await UniTaskAsyncEnumerable.EveryUpdate().ForEachAsync UniTask notation for Update loop
    And I wanted to know what would be the way to convert the following code to the UniTask notation (how to use multiple loops from different PlayerLoopTimings)
    private void Update()
    {
        ReadInput();
    }
    private void FixedUpdate()
    {
        CharacterUpdate();
    }
    Image
    Andrei Müller (Andy Miira)
    @andreiagmu

    I tried doing like this

    private async UniTaskVoid Start()
    {
        var cancellationToken = this.GetCancellationTokenOnDestroy();
    
        await UniTaskAsyncEnumerable.EveryUpdate().ForEachAsync(_ =>
        {
            ReadInput();
    
        }, cancellationToken);
    
        await UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate).ForEachAsync(_ =>
        {
            CharacterUpdate();
    
        }, cancellationToken);
    }

    But then, the second await UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate) never gets called

    In this case, ReadInput() and CharacterUpdate() are declared as void methods

    Image
    Andrei Müller (Andy Miira)
    @andreiagmu
    Alright, I think await UniTask.WhenAll() it's just what I was looking for (to do concurrent task processing)
    private async UniTaskVoid Start()
    {
        var cancellationToken = this.GetCancellationTokenOnDestroy();
    
        var updateTask = UniTaskAsyncEnumerable.EveryUpdate().ForEachAsync(_ =>
        {
            ReadInput();
    
        }, cancellationToken);
    
        var fixedUpdateTask = UniTaskAsyncEnumerable.EveryUpdate(PlayerLoopTiming.FixedUpdate).ForEachAsync(_ =>
        {
            CharacterUpdate();
    
        }, cancellationToken);
    
        await UniTask.WhenAll(updateTask, fixedUpdateTask);
    }
    Image
    Alexander Wieser
    @crystalbyte
    Is there a way to await inside the create method?`
       private IObservable<T> Request<T>(string route, string method, object body, HttpOptions options) {
    
                return Observable.Create<T>(observer => { // async missing
                    //  Set default values
                    var request = new UnityWebRequest(route, method);
                    foreach (var header in options.Headers) {
                        request.SetRequestHeader(header.Key, header.Value);
                    }
    
                    foreach (var interceptor in interceptors) {
                        await interceptor.InterceptAsync(request);
                    }
    
                    var response = await request.SendWebRequest().AsObservable();
    Image
    Per Hornshøj-Schierbeck
    @Hojou
    I just picked this library up and it doesn't seem to work for my unity 2020 project - i also see the last update to the library is over a year ago - was support stopped?
    I get this error when i try to use a ReactiveProperty:
    error CS0246: The type or namespace name 'ReactiveProperty<>' could not be found (are you missing a using directive or an assembly reference?)
    I'm on Unity 2020.1.17f1
    I have these using statements:
    using System.Collections.Generic;
    using System.Linq;
    using UnityEngine;
    Image
    Artur Dębkowski
    @ekhart
    try to add using UniRx; to the script
    Image
    kgc00
    @kgc00

    Hi guys,

    new to unirx, sorry if this has been asked- Is there some preferred way to fire off an event or method at under specific conditions? For example

    // hp = reactiveproperty<float>
    if (hp <= 0) execute()

    I'm currently messing around with ReactiveProperties and the MessageBroker to try and achieve this but am not sure if this is the correct aproach

                hp.Select(x => x <= 0).Subscribe(x => {
                    if (x) {
                        Debug.Log("Fire!");
                        MessageBroker.Default.Publish(new Empty());
                        hp.Dispose();
                    }
                }).AddTo(this);

    Does this seem like an okay way to achieve this functionality?

    Image
    kgc00
    @kgc00

    ended up here:

    gameObject.UpdateAsObservable().SampleFrame(30).Where(_ => hp <= 0).Distinct().Subscribe(_ => {
                    Debug.Log("Fire!");
                    MessageBroker.Default.Publish(new Empty());
                }).AddTo(this);

    any way to make it so everytime it goes from > 0 to <= 0 it fires?

    Image
    kgc00
    @kgc00
    so like:
    100 => 0
    fires once
    0 => 20
    20 => 0
    fires once
    etc
    Image
    Jonathan Bro
    @Nomy1
    If you give it a buffer for the previous value then you can compare it with the next value and determine if it's going from positive to negative
    Image
    kgc00
    @kgc00
    Thanks! I'll try it out
    Image
    kgc00
    @kgc00
    Turns out the pairwise operator was a bit simpler for that usecase so i went with that instead =)
    Image
    Jonathan Bro
    @Nomy1
    What's pairwise? A tuple?
    Image
    kgc00
    @kgc00
    exactly, it combines the last 2 events in the stream so you can do something like:
    x.OnValueChangedAsObservable()
                    .Where(_ => hp <= 0)
                    .Pairwise()
                    .Where(x => x.Current && !x.Previous)
                    .Subscribe(_ => HandleEvent());
    Image
    vbandi
    @vbandi
    Unfortunately, it seems like UniRX has been abandoned. Does anyone know if there's a public/community fork that's being kept up-to-date?
    Image
    sparkdsd
    @sparkdsd

    Hi guys!

    var a = new ReactiveProperty<bool>();
    _button.OnClickAsObservable().Subscribe(_ => a.Value = !a.Value); 
    
    a.SelectMany(v => v ? Observable.EveryUpdate().Select(_ => true) : Observable.Return(false)).Subscribe(v => Debug.Log(v));

    I only want Debug.Log work if a.Value==true and when a.Value==false nothing should happen
    But with this code if I switch a.Value = false - Console once print false and then continuously true ( obviously from EveryUpdate )

    Image
    Gwendal Broudin
    @GwendalBroudin
    Hi @neuecc thanks for these amazing library, I would love to use these in a long term industrial project. Unfortunately, as @vbandi said, there not a lot of activity those days, is the project still maintained?