- Home /
Load can only be called from the main thread
I have far too much code to post it all, so i'll post the basic bits and hope for the best. My main script creates a 'LevelEditor' which some way down the line creates pStaticPlatform (a resource). It does so with this:
 var e : LevelEditor;
 function Start ()
 {
     e = new LevelEditor();
 }
 function LevelEditor()
 {
         m = new Map();
     m.addPlatform(new Platform(true,0,0,0));
 }
 
 function Platform(s : boolean, a : float, b : float, c : float)
 {        
     var d : GameObject;
     d = UnityEngine.Object.Instantiate(Resources.Load("pStaticPlatform1")) as GameObject;
 }
Which gives the error: ArgumentException: Load 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. UnityEngine.Resources.Load (System.String path) (at C:/BuildAgent/work/14194e8ce88cdf47/Runtime/ExportGenerated/Editor/BaseClass.cs:1559) Platform..ctor (Boolean s, Single a, Single b, Single c) (at Assets/Classes/Platform.js:16) LevelEditor..ctor () (at Assets/Classes/LevelEditor.js:12)
If i declare the LevelEditor as static, this error goes away. Why, what does this all mean?
Your answer
 
 
             Follow this Question
Related Questions
How do I load my txt file in iOS 1 Answer
How to load nested prefab? 1 Answer
How to load resource by asynchronization? 0 Answers
Import a prefab from file at runtime? 1 Answer
load file from Xcode 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                