Skip to content
This repository has been archived by the owner on Feb 16, 2024. It is now read-only.

"NullReferenceException" in Observable.EveryLateUpdate when Disabling Domain Reloading #490

Open
kyubuns opened this issue May 6, 2021 · 1 comment · May be fixed by #491
Open

"NullReferenceException" in Observable.EveryLateUpdate when Disabling Domain Reloading #490

kyubuns opened this issue May 6, 2021 · 1 comment · May be fixed by #491

Comments

@kyubuns
Copy link

kyubuns commented May 6, 2021

When I set Domain Reload to disable in PlayerSettings > Editor > Enter PlayMode Options,
the following code throws NullReferenceExteption.
After setting Domain Reload to disable, enter PlayMode twice.

NullReferenceException: Object reference not set to an instance of an object
UniRx.MainThreadDispatcher.LateUpdateAsObservable () (at Assets/Plugins/UniRx/Scripts/UnityEngineBridge/MainThreadDispatcher.cs:643)
UniRx.Observable.EveryLateUpdate () (at Assets/Plugins/UniRx/Scripts/UnityEngineBridge/Observable.Unity.cs:717)
Test.Start () (at Assets/Test.cs:8)
using UniRx;
using UnityEngine;

public class Test : MonoBehaviour
{
    public void Start()
    {
        Observable.EveryLateUpdate()
            .Subscribe(x => Debug.Log("a"));
    }
}

Environment

  • Unity2020.3.4f1
@AlexMeesters
Copy link

AlexMeesters commented May 31, 2022

Right now, what happens is, UniRX is still trying to call LateUpdate on your object. But it doesn't exist anymore.
This also happens during runtime if you decide to remove the object in the inspector.

You could make it work by adding AddTo(this), so it unsubscribes when the GameObject has been destroyed:

 Observable.EveryLateUpdate()
            .Subscribe(x => Debug.Log("a"))
            .AddTo(this);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants