1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. Unity 5.6 is now released.
    Dismiss Notice
  3. Check out all the fixes for 5.5 in patch releases 1 & 2.
    Dismiss Notice
  4. Get further faster with the Unity Plus Accelerator Pack, free for new Unity Plus subscribers for a limited time. Click here for more details.
    Dismiss Notice
  5. Learn how you'll soon be able to publish your games to China in four simple steps with Xiaomi. Sign up now for early access.
    Dismiss Notice

C# 6.0

Discussion in 'Scripting' started by supremegrandruler, Mar 27, 2015.

  1. timintal

    timintal

    Joined:
    Jul 23, 2012
    Posts:
    8
    I have an issue with unity 5.6. As soon as I import C# 6.0 support into my project all log errors has no line number where exactly in script this error occured.
    Before importing: [​IMG]

    After importing: [​IMG]

    Is there a way to fix this as it really slows development process?
     
  2. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,231
    Usually async/await code looks simpler than one using coroutines. I would rewrite it this way:
    Code (CSharp):
    1. public async void OnButtonClicked() // async methods work fine as direct event handlers
    2. {
    3.     something.StartTheThing();
    4.     while (something.IsDone == false)
    5.     {
    6.         await 0;
    7.     }
    8.     DoStuffThatNeedsTheMainThread(); // will run in the main thread
    9. }
    However, if StartTheThing() returns UnityEngine.AsyncOperation, it can be even simplier:
    Code (CSharp):
    1. public async void OnButtonClicked()
    2. {
    3.     await something.StartTheThing();
    4.     DoStuffThatNeedsTheMainThread(); // will run in the main thread
    5. }
    If it returns something else, other than void, it's possible to write an awaiter for that return type so that the previous example could also work. It's also possible to write an awaiter for the type of that 'something' itself, if it would make sense. So we could write
    Code (CSharp):
    1. public async void OnButtonClicked()
    2. {
    3.     something.StartTheThing();
    4.     await something;
    5.     DoStuffThatNeedsTheMainThread(); // will run in the main thread
    6. }
    Such an awaiter wouldn't be much different from the AsyncOperationAwaiter that you can find inside AsyncTools.cs.
     
    Last edited: Apr 21, 2017 at 3:52 PM
    makeshiftwings likes this.
  3. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,231
    There must be something wrong with debug symbols. Are you on Mac or Windows?
     
  4. timintal

    timintal

    Joined:
    Jul 23, 2012
    Posts:
    8
    I'm on Mac, and my colleague on Windows doesn't have this problem. May be something wrong with Mono.
     
  5. alexzzzz

    alexzzzz

    Joined:
    Nov 20, 2010
    Posts:
    1,231
    You must be using Roslyn compiler. Roslyn can't generate debug symbols in 'pdb' format on Mac, and the 'portable pdb', that it can generate, is not supported yet by Mono. So the solution is to switch to Mono C# 6 compiler via deleting the Roslyn folder.
     
  6. buistvo

    buistvo

    Joined:
    Friday
    Posts:
    1
    Great work with that pack!
    I have a problem: VS2017 compiles my code but unity not. Is says:

    Assets\CSharp vNext Support\AsyncTools\AsyncTools.cs(13,29): error CS0433: The type 'Lazy<T>' exists in both 'System.Threading, Version=1.0.2856.102, Culture=neutral, PublicKeyToken=31bf3856ad364e35' and 'nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb'

    anyone knows how to fix this?
     
    Last edited: Apr 21, 2017 at 9:00 PM
  7. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    233
  8. Vedrit

    Vedrit

    Joined:
    Feb 8, 2013
    Posts:
    475
    Wait, I thought C# 6.0 support wouldn't be included until Unity 2017