I’m having trouble debugging a non-fatal Exception that suddenly appeared after upgrading from 2022.3.21f1 to 2022.3.50f1 (LTS). The exception occurs every time I click an “OK” button in a popup dialog prefab to dismiss the prefab (ie, “Destroy(dialogGO);”
Full stack:
MissingReferenceException: The object of type 'GameObject' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEngine.InputSystem.UI.InputSystemUIInputModule.ProcessPointerMovement (UnityEngine.InputSystem.UI.ExtendedPointerEventData eventData, UnityEngine.GameObject currentPointerTarget) (at ./Library/PackageCache/com.unity.inputsystem@1.11.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:476)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.ProcessPointerMovement (UnityEngine.InputSystem.UI.PointerModel& pointer, UnityEngine.InputSystem.UI.ExtendedPointerEventData eventData) (at ./Library/PackageCache/com.unity.inputsystem@1.11.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:402)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.ProcessPointer (UnityEngine.InputSystem.UI.PointerModel& state) (at ./Library/PackageCache/com.unity.inputsystem@1.11.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:352)
UnityEngine.InputSystem.UI.InputSystemUIInputModule.Process () (at ./Library/PackageCache/com.unity.inputsystem@1.11.0/InputSystem/Plugins/UI/InputSystemUIInputModule.cs:2257)
UnityEngine.EventSystems.EventSystem.Update () (at ./Library/PackageCache/com.unity.ugui@1.0.0/Runtime/EventSystem/EventSystem.cs:530)
Some observations after the error occurs:
- Error is spammed at a high rate, as if it’s coming from an internal Update() method
- The app mostly runs normally after the error starts, however mouse pointer events (OnPointerEnter, onClick) stop working, but other UI navigation continue to work fine.
- Reproduces in Unity player, and standalone Mac build.
Here is the code to start the dialog:
private void DialogTest() {
GameObject dialogGO = Instantiate(Resources.Load<GameObject>("Prefabs/MyDialog"), transform);
Dialog dialogScript = dialogGO.GetComponent<Dialog>();
dialogScript.dialogButtonCallback = () => {
Destroy(dialogGO);
// MissingReferenceException!!
};
}
And here is the MyDialog.cs script attached to the prefab:
public class MyDialog : MonoBehaviour
{
public delegate void DialogButtonCallback();
public DialogButtonCallback dialogButtonCallback { get; set; }
void Awake()
{
}
public void OnButtonClicked()
{
if (dialogButtonCallback != null)
{
dialogButtonCallback();
}
}
}
Does anyone have any thoughts as to why calling “Destroy(dialogGO)” could start producing this error on the latest Unity engine?