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];