先說(shuō)嚴(yán)重性

image.png
造成LogStringToConsole高調(diào)用(不排除有一部分是代碼打印的)
You are trying to create a MonoBehaviour using the 'new' keyword.
This is not allowed. MonoBehaviours can only be added using AddComponent().
該錯(cuò)誤出自u(píng)nity的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,問(wèn)題原因就是在B類中通過(guò)New 的方式使用A component
雖然console不會(huì)報(bào)錯(cuò),但會(huì)給性能帶來(lái)比較大的影響,component畢竟是畢竟耗性能的
public class A : MonoBehaviour {
...
}
private A a = new A();
public class B: MonoBehaviour {
...
}