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:  
  1. public class Node : ScriptableObject
  2.  {
  3.         public int[] data;
  4.  }
  5.  
  6. List<Node> dataset;
  7. ..
  8.  
  9. // Error, this fails inside of thread
  10. Node node = dataset[i];

this works:

Code:  
  1. public interface INodeData
  2.  {
  3.         int[] data { get; }    
  4.  }
  5.  
  6. public class Node : ScriptableObject, INodeData
  7.  {
  8.         public int[] data;
  9.  }
  10.  
  11. List<INodeData> dataset;
  12. ..
  13.  
  14. // this works! inside of thread
  15. INodeData node = dataset[i];

Error: CompareBaseObjectsInternal can only be called from the main thread的更多相关文章

  1. Unity3d报告奇怪的错误CompareBaseObjectsInternal can only be called from the main thread.

    其中使用了该项目.NET的Async Socket代码.后来不知道什么时候这个奇怪的错误的出现: CompareBaseObjectsInternal can only be called from ...

  2. [原]openstack-kilo--issue(十九) ImportError: Could not import settings 'openstack_dashboard.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named main

    查看此问题的时候请先查看 这个问题包含在(十)中,此篇只是从(十)中分离出来 openstack-kilo--issue(十)ERROR: openstack Unable to establish ...

  3. [java] [error] java.lang.OutOfMemoryError: unable to create new native thread

    前言 最近公司的服务器出现了oom的报错,经过一番排查,终于找到了原因.写下这篇博客是为了记录下查找的过程,也是为了帮助那些跟我门遇到的情况相同的人可以更快的寻找到答案. 环境 系统:linux(ce ...

  4. Unity 中 使用c#线程

    使用条件   天下没有免费的午餐,在我使用unity的那一刻,我就感觉到不自在,因为开源所以不知道底层实现,如果只是简单的做点简单游戏,那就无所谓的了,但真正用到实际地方的时候,就会发现一个挨着一个坑 ...

  5. SFTP &amp; FTP Upload

    简述 >> FTP: 1. Install FTP service on Linux(Red Hat) as root user    [root]# yum install ftp 2. ...

  6. CompletableFuture的使用例子

    1. CompletableFuture的介绍 在Java8时被引入,在包java.util.concurrent下,是Java多线程编程中的一个类,扩展了Future中很多功能,Completabl ...

  7. 【Linux】关于Linux的系统编程总结

    作者:李春港 出处:https://www.cnblogs.com/lcgbk/p/14673383.html 目录 系统编程 (一)进程 1.进程的概念 2.进程函数接口 (1)fork()在进程内 ...

  8. error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用

    MSVCRTD.lib(crtexew.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainCRTStartup 中被引用 Debug ...

  9. MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号 _WinMain@16,该符号在函数 ___tmainC (转)

    一.问题描述 我所使用的编程环境:VS2010 出现的问题如下: MSVCRTD.lib(mfc.obj) : error LNK2019: 无法解析的外部符号_WinMain@16,该符号在函数 _ ...

随机推荐

  1. VMware 安装LINUX系统(一)

    我用的是WORKSTATION 15 PRO https://www.vmware.com/asean/products/workstation-pro/ 1.安装LINUX 打开Vmware,点击创 ...

  2. JS排序之冒泡排序

    冒泡排序的两种策略: <script>// 第一种思路:// 一个数组中的数据,拿第一个和剩下的依次进行对比,数值小的赋值给第一个,一轮比较过后,则数值小的放在最前边.// 第二轮比较,则 ...

  3. 利用JavaScript的%做隔行换色

    <html> <head> <meta charset="utf-8"> <title>无标题文档</title> &l ...

  4. 08.十分钟学会JSP传统标签编程

    一.认识标签 1,说明:传统标签编程在开发中基本用不到,学习标签编程主要还是为了完善知识体系. 2,标签的主要作用:移除或减少jsp中的java代码 3,标签的主要组成部分及运行原理 4,简单标签示例 ...

  5. 【从零开始】【Java】【0】装软件些

    闲聊 其实最先写的是1,所以拐回头写的只能是0了. 因为要在不同的电脑上搞这个东西,必然涉及到装机,当然只是装我们用的这些,且是最基础的部分了. 大晚上的睡不着觉,起来,大概1个小时全部搞定,随便记下 ...

  6. setTimeout()传带有参数的函数

    w3cshool里的解释:setTimeout() 方法用于在指定的毫秒数后调用函数或计算表达式,语法:setTimeout(code,millisec). 也就是说,第一个参数可以是字符串形式的Ja ...

  7. 动态给某一个元素添加active

    <li class="one_data" data-id='+ navGroup.self_first_nav[i].id +'><a  href='+ navG ...

  8. 团体程序设计天梯赛-练习集-L1-025. 正整数A+B

    L1-025. 正整数A+B 本题的目标很简单,就是求两个正整数A和B的和,其中A和B都在区间[1,1000].稍微有点麻烦的是,输入并不保证是两个正整数. 输入格式: 输入在一行给出A和B,其间以空 ...

  9. 洛谷P3275 [SCOI2011]糖果_差分约束_判负环

    Code: #include<cstdio> #include<queue> #include<algorithm> using namespace std; co ...

  10. 洛谷P2038 无线网络发射器选址 水题 枚举

    刚开始边界写错了(将128写成127). 注意n <= 20,所以可以每读入一个点就将其周边更新,这样最多也只会有 40 * 40 * 20 种位置需要被枚举. Code: #include&l ...