首页 > 代码库 > Error: CompareBaseObjectsInternal can only be called from the main thread
Error: CompareBaseObjectsInternal can only be called from the main thread
Posted: 01:39 PM 06-17-2013
hi, we’re working on a project where we need to do some calculations on a separate thread. The data we need for the calculations is stored on a scriptable object. We use the scriptable object so that we can serialize the data and save it as an asset file. However, when we tried to access the data from a separate thread we get the following error.
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.
For our purposes we only need to read the data. One of the things that we tried to do to get around this was to use an interface. It appears that if you use an interface as a reference to the object then you’re able to access the data without getting that error. For example
Code:
public class Node : ScriptableObject { public int[] data; } List<Node> dataset; .. // Error, this fails inside of thread Node node = dataset[i];
this works:
Code:
public interface INodeData { int[] data { get; } } public class Node : ScriptableObject, INodeData { public int[] data; } List<INodeData> dataset; .. // this works! inside of thread INodeData node = dataset[i];
Error: CompareBaseObjectsInternal can only be called from the main thread
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。