Unity-Technologies / arfoundation-samples

Example content for Unity projects based on AR Foundation
Other
2.98k stars 1.11k forks source link

[Bug] ARTrackableManager.trackablesChanged is null after creating the manager from script #1121

Closed KyryloKuzyk closed 6 months ago

KyryloKuzyk commented 7 months ago

Describe the bug ARTrackableManager.trackablesChanged is null after creating the manager from a script. And there is no way to assign a non-null value to trackablesChanged because its setter is private.

To Reproduce

#if TEST_FRAMEWORK_INSTALLED
using NUnit.Framework;
using UnityEngine;
using UnityEngine.XR.ARFoundation;

public class EditModeTests {
    #if AR_FOUNDATION_6_0_OR_NEWER
    [Test]
    public void TrackablesChangedNullRefBug() {
        var go = new GameObject();
        try {
            var planeManager = go.AddComponent<ARPlaneManager>();
            Assert.IsNotNull(planeManager.trackablesChanged); // this assertion fails
        } finally {
            Object.DestroyImmediate(go);
        }
    }
    #endif
}
#endif

Proposed fix Set the default value in field declaration.

public UnityEvent<ARTrackablesChangedEventArgs<TTrackable>> trackablesChanged { get; private set; } = new UnityEvent<ARTrackablesChangedEventArgs<TTrackable>>();

Setup

andyb-unity commented 7 months ago

Thanks @KyryloKuzyk. We're on it.

andyb-unity commented 7 months ago

We just merged this in. Will be in 6.0.0-pre.5. Our current thinking is to cut at least one more pre-release before we ship 6.0.0.

andyb-unity commented 6 months ago

Fixed in 6.0.0-pre.5. Feel free to re-open this issue if you have further concerns.