- Home /
Prefabs are instantiated in editor but not in executable
I have a prefab (item) instantiated on the ground when an enemy dies. Everything works fine in the editor, but when I try building the project, nothing is spawned. All my prefabs are in the Resources folder (in the Assets folder). This is the code to assign the dropped item :
item = Resources.Load ("Prefabs/Weapons/LightMachineGun");
The output_log.txt file gives me a NullReferenceException.
Sorry if the problem is obvious. Thanks.
Answer by Loius · Nov 13, 2010 at 04:07 AM
item = Instantiate( Resources.Load(thing) );
Resources.Load returns an Object; that is, a reference to the object in the Project. You need to use Instantiate to create a copy in the Hierarchy.
Answer by StephanK · Jul 17, 2010 at 05:26 AM
Are the assets that are used by your prefab (model,textures etc.) also in the Resources folder?
Once they are in the resources folder, do I have to load each one of them (audio clip, textures used by scripts, etc)?
No, but they must be there, otherwise the prefab can't be instantiated.
Just as a test, I moved all my assets in the Resources folder and nothing happens. Thanks for the suggestion though.
Your answer
Follow this Question
Related Questions
Instantiation working in editor, not in build. 0 Answers
Editor Resources vs In Game Resources 0 Answers
Resources.Load() or Prefab manager? 1 Answer
Instantiate in Editor 1 Answer