You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBeha...

先说严重性


image.png

造成LogStringToConsole高调用(不排除有一部分是代码打印的)

You are trying to create a MonoBehaviour using the 'new' keyword.  
This is not allowed.  MonoBehaviours can only be added using AddComponent(). 

该错误出自unity的Editor.log日志中

macOS   ~/Library/Logs/Unity/Editor.log
Windows C:\Users\username\AppData\Local\Unity\Editor\Editor.log

word is poor show me the code,问题原因就是在B类中通过New 的方式使用A component
虽然console不会报错,但会给性能带来比较大的影响,component毕竟是毕竟耗性能的

public class A : MonoBehaviour {
  ... 
}
private A a = new A();
public class B: MonoBehaviour {
  ... 
}
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容