CompareBaseObjectsInternal can only be called from the main thread.
CompareBaseObjectsInternal can only be called from the main thread.
Constructors and field initializers will be executed from the loading thread when loading a scene.
Don't use this function in the constructor or field initializers, instead move initialization code to the Awake or Start function.
...
public OtherScript m_otherScript;
...
var request = WebRequest.Create(url);
request.BeginGetResponse(result => {
if (m_otherScript != null) // ERROR HERE!!!
{
// some logic here
}
});
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
One of the method to resolve above problem is move the anyc callback function to Update function. Of course you need to make sure this script is enabled. Sometimes you spend a lots of time to debug why callback function is not called, and finally you find that the whole gameobjects were disabled by other logic. This is what you need take care when you do such modification.
void Update()
{
if (result != null) {
if (m_otherScript != null)
{
// some logic here
}
result = null;
}
// ...
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
评论
发表评论