Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

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

Discussion in '2019.1 Beta' started by 479813005, Apr 5, 2019.

  1. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    71
    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.

    2. 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.

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.Threading.Tasks;
    5.  
    6. public class AsyncBug : MonoBehaviour
    7. {
    8.     // Start is called before the first frame update
    9.     async void Start()
    10.     {
    11.         Debug.Log(1);
    12.         await Task.Delay(10000);
    13.         Debug.Log(2);
    14.         GameObject go = GameObject.CreatePrimitive(PrimitiveType.Cube);
    15.         Debug.Log(3);
    16.     }
    17. }
    18.  
     
    Last edited: Apr 5, 2019
  2. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    71
    Errors can be reproduced in all versions.
     
    Last edited: Apr 5, 2019
  3. 479813005

    479813005

    Joined:
    Mar 18, 2015
    Posts:
    71
  4. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,123
    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:
    https://forum.unity.com/threads/asy...e-in-the-editor-potentially-dangerous.591235/

    @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.
     
    479813005 likes this.