Unity 升级到2018之后出现TargetException: Non-static method requires a target.错误的问题

在Unity升级到2018之后,发现工程出现了一个这样的错误:

TargetException: Non-static method requires a target.

System.Reflection.MonoMethod.Invoke (System.Object obj, System.Reflection.BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at :0)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at :0)
UnityEditor.EditorAssemblies.ProcessInitializeOnLoadMethod (System.Reflection.MethodInfo method) (at C:/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:116)
UnityEditor.EditorAssemblies.ProcessInitializeOnLoadAttributes () (at C:/buildslave/unity/build/Editor/Mono/EditorAssemblies.cs:135)

看路径定位似乎是Unity内部的问题


实际上,这是由于Unity对[InitializeOnLoadMethod]规则的变更引起的.

在2018.1.2之前,[InitializeOnLoadMethod]特性似乎不在乎所定义的方法是否静态方法,而在2018.1.2之后,[InitializeOnLoadMethod]所定义的方法必须为静态方法,否则会报上述错误.

你只要在工程中搜索[InitializeOnLoadMethod]的引用,将非静态的方法排除或者修改即可

你可能感兴趣的:(Unity 升级到2018之后出现TargetException: Non-static method requires a target.错误的问题)