2

I have Unity 2018.1.9f2 and I downloaded the Unity ml agents and added the folder to my unity project. But When I try to run the '3DBall' scene I get this error in the console:

Assets/ml-agents-master/UnitySDK/Assets/ML-Agents/Scripts/Brain.cs(79,25): error CS1644: Feature null propagating operator' cannot be used because it is not part of the C# 4.0 language specification. When I double click it then it opens the VS and brainBatcher?.SendBrainInfo(name, agentInfos); is underlined. and when I hover over the code it says Feature 'null propagating operator' is not available in C# 4. Please use language version 6 or greater.

I tried to follow the answer from anther similar question: Unity Visual Studio C# version synchronization. So I used unity-c-5.0-and-6.0-integration and that error was not displayed but I got 150+ other errors.

Any help will be much appreciated.

Samoeo Molm
  • 35
  • 2
  • 5
  • If the code uses C# syntax such as `?.`, then indeed it'll need a more recent compiler, which you've already tried; most likely the "150+ other errors" are just missing library/package references, so it is probably only a couple of actual "problems" here – Marc Gravell Feb 04 '19 at 15:15
  • [Did you set the langage version in VS](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version#set-the-language-version-in-visual-studio)? I'm not into unity ... not sure if it helps ;) – nilsK Feb 04 '19 at 15:18
  • @MarcGravell most of it is because of the google. I get something like this `Assets\ml-agents-master\UnitySDK\Assets\ML-Agents\Scripts\SocketCommunicator.cs(1,7): error CS0246: The type or namespace name 'Google' could not be found (are you missing a using directive or an assembly reference?)` any idea of what should I do ? thanks for your time – Samoeo Molm Feb 04 '19 at 15:24
  • @nilsK I don't think this is the problem. But thanks though :) – Samoeo Molm Feb 04 '19 at 15:25
  • @SamoeoMolm it literally tells you... "are you missing a using directive or an assembly reference?" - now, since we can assume the code is meant to compile, that means we can probably rule out the "using directive" possibility, so that means you're most likely missing - as I said - a reference. In this case, to a google library. Without context (i.e. what comes immediately after the `Google`), that could be just about anything... Google have a lot of libraries. – Marc Gravell Feb 04 '19 at 15:25
  • @MarcGravell I tried to search for google in the ML-Agents and I found this `Google.Protobuf` so there is a google library :/ How can I know which library is missing ? Thanks again – Samoeo Molm Feb 04 '19 at 15:29
  • 1
    Did you switch to `.NET 4.6` ? (`PlayerSettings -> Other Settings -> Scripting runtime Version`) – derHugo Feb 04 '19 at 15:29

2 Answers2

12

Make sure your Player Settings / Scripting Runtime Version is set to .NET 4.x not .NET 3.5

scripting runtime version

zambari
  • 4,797
  • 1
  • 12
  • 22
1

Why not just remove the ?

In my case, the following change fixes the build even using .net 3.5 framework


Action<DeleteObjectsResponse, string> result;

// Change:

//result?.Invoke(null, responseObj.Exception.ToString());

// To:

if (result != null)
   result.Invoke(null, responseObj.Exception.ToString());
adiga
  • 34,372
  • 9
  • 61
  • 83
Nuo Chen
  • 11
  • 1