Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Mcs in Unity 2018.1.2 emitting incorrect warnings

Discussion in 'Editor & General Support' started by MapMan, May 31, 2018.

  1. MapMan

    MapMan

    Joined:
    Oct 27, 2013
    Posts:
    38
    Hi

    In Unity 2018.1.2, the compiler is emitting incorrect warnings about an asynchronous call not being awaited, e.g. when incrementing an integer value or calling a method which returns an int. For that reason, I had to suppress the warning globally (with mcs.rsp). The warning in question is 4014 - Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.

    Regards
     
  2. liortal

    liortal

    Joined:
    Oct 17, 2012
    Posts:
    3,562
    Can you show a code example that results in this warning ?
     
  3. MapMan

    MapMan

    Joined:
    Oct 27, 2013
    Posts:
    38
    Add this script to your project to see the warning:

    Code (CSharp):
    1. using System.Threading.Tasks;
    2. using UnityEngine;
    3.  
    4. public class ExampleScript : MonoBehaviour
    5. {
    6.     async Task ExampleMethodAsync()
    7.     {
    8.         var i = 0;
    9.         i++;  // Unity emits a warning that this line should be awaited
    10.  
    11.         // This is an async method so await something to avoid CS1998 warning
    12.         await Task.Delay( 0 );
    13.     }
    14. }
    15.