neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.01k stars 895 forks source link

NextFrame() skips second frame #515

Open subGlitch opened 2 years ago

subGlitch commented 2 years ago

Repro: Create empty project, import UniRx, add new GameObject to the scene with Test component, containing following code:

public class Test : MonoBehaviour
{
    void Start()
    {
        Debug.Log( $"Cur frame: {Time.frameCount}" );

        Observable
            .NextFrame()
            .Subscribe( _ => Debug.Log( $"Next frame: {Time.frameCount}" ) );
    }
}

Result: After entering Play Mode there will be following output in the console:

Cur frame: 1
Next frame: 3

Expected behavior:

Cur frame: 1
Next frame: 2