【问题标题】:error CS1644: Feature `null propagating operator' cannot be used because it is not part of the C# 4.0 language specification错误 CS1644:无法使用功能“空传播运算符”,因为它不是 C# 4.0 语言规范的一部分
【发布时间】:2019-02-04 15:09:15
【问题描述】:

我有 Unity 2018.1.9f2,我下载了 Unity ml 代理并将文件夹添加到我的统一项目中。但是当我尝试运行“3Dball”场景时,我在控制台中收到了这个错误:

Assets/ml-agents-master/UnitySDK/Assets/ML-Agents/Scripts/Brain.cs(79,25): error CS1644: Feature null propagating operator' 不能使用,因为它不是 C# 4.0 的一部分语言规范。当我双击它时,它会打开 VS 并且 brainBatcher?.SendBrainInfo(name, agentInfos); 带有下划线。 当我将鼠标悬停在代码上时,它会显示Feature 'null propagating operator' is not available in C# 4. Please use language version 6 or greater.

我试图遵循另一个类似问题的答案:Unity Visual Studio C# version synchronization。所以我使用了 unity-c-5.0-and-6.0-integration 并没有显示该错误,但我得到了 150 多个其他错误。

任何帮助将不胜感激。

【问题讨论】:

  • 如果代码使用 C# 语法,例如 ?.,那么确实需要更新的编译器,您已经尝试过;很可能“150 多个其他错误”只是缺少库/包引用,所以这里可能只是几个实际的“问题”
  • Did you set the langage version in VS?我不团结......不确定它是否有帮助;)
  • @MarcGravell 大部分是因为谷歌。我得到类似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?) 的东西,知道我该怎么做吗?感谢您的宝贵时间
  • @nilsK 我认为这不是问题所在。不过还是谢谢 :)
  • 你切换到.NET 4.6了吗? (PlayerSettings -> Other Settings -> Scripting runtime Version)

标签: c# unity3d ml-agent


【解决方案1】:

确保您的播放器设置/脚本运行时版本设置为 .NET 4.x 而不是 .NET 3.5

【讨论】:

  • 你是个混蛋。我整天都在这上面度过。 Thaaaanks 太棒了。
  • 我们配不上你
【解决方案2】:

为什么不直接删除?

在我的例子中,即使使用 .net 3.5 框架,以下更改也修复了构建


Action<DeleteObjectsResponse, string> result;

// Change:

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

// To:

if (result != null)
   result.Invoke(null, responseObj.Exception.ToString());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-05
    • 2017-12-09
    • 1970-01-01
    • 2016-04-14
    • 2020-11-18
    • 1970-01-01
    相关资源
    最近更新 更多