(Case 1143604) The asynchronous function callback method is passed from the Play mode to the Editor

https://fogbugz.unity3d.com/default.asp?1143604_v8qe8bvth3mn1iog.

  1. What happened

The asynchronous function callback method is passed from the Play mode to the Editor mode.
Expected behavior: Forced to stop all asynchronous functions when switching Editor/Play mode.

  1. How we can reproduce it using the example you attached

Play SampleScene, Stop Play mode. Wait for 10s and will create a cube in the current scene in editor mode. It’s wrong.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Threading.Tasks;

public class AsyncBug : MonoBehaviour
{
    // Start is called before the first frame update
    async void Start()
    {
        Debug.Log(1);
        await Task.Delay(10000);
        Debug.Log(2);
        GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
        Debug.Log(3);
    }
}

Errors can be reproduced in all versions.

I receive https://issuetracker.unity3d.com/issues/async-method-continues-to-run-in-the-edit-mode-when-exiting-play-mode。:(

Yep, this makes async methods very dangerous and ruins the ‘sandbox’ nature of the editor/play mode.

I’ve posted about this in a previous beta, here:

@mkderoy replied:

Though there is bug reports from as far back as the start of 2018 , and there isn’t any more movement on this issue, so I guess don’t hold your breath for a solution from Unity any time soon.

1 Like