I have a question for AddComponent
I created a new GameObject and tried to call AddComponent[new_GameObject].Call(MyClass::BNMCustomClass.type);. The following code can run correctly:
However, when I used a thread to load the initialization without changing anything else, the program crashed when executing AddComponent.
There were no crash logs.
What is this causing AddComponent to crash?
I changed sleep(1) to usleep(1) and it works again.
Calling unity methods outside of main thread is dangerous. This is reason of crash. And you can't call it using AddOnLoadEvent too, this event is too early. Hook sth, like Internal_SceneLoaded and create object here.
yes, I hook AdsManager(MonoBehaviour) .ctor method in OnLoaded_SomeMethod,and create object here.
Does this still count as calling a unity method outside of the main thread?
I tried to use AttachIl2Cpp(),but this still crash ,when Code executed to AddComponent[new_GameObject].Call(MyClass::BNMCustomClass.type);
From the logs, it seems that he is on the main thread
Try use BNM v2.1.0
Running it in a sub-thread causes all sorts of weird problems, and I've given up on it