Resources folder empty in Build and public variables NullReferenceException
I got 2 big problems that after a lot of research I´m unable to solve.
First problem: I got 5 xml files and a sub-folder inside the Resources folder but when I build my project, the Resources folder is empty (well, only two unity files in there: unity default resources and unity_builtin_extra. So I can´t access my xml files when I do: Resources.Load, anywhere on my code.
I post images to clarify:
Second problem: As Resources file was not working I decided to use public variables for my xml files declaring: public TextAsset myXmlDoc, but I realize that, only when I build this isn´t working as it gets NullReferenceException as if my public TextAsset variable wasn't assigned by me (wich is not true)
I post images and code to clarify:
public class LoadXml_Narrator : MonoBehaviour {
NarratorTextClass narratorClass;
public TextAsset file;
void Awake()
{
print("Xml file " + file);
}
}
This is the output log of my Build:
NullReferenceException: Object reference not set to an instance of an object at LoadXml_Narrator.Awake () [0x0001d] in D:\Projects\PC\Majorel_\Majorel_\Assets\Scripts\XML\Narrator\LoadXml_Narrator.cs:20
(Filename: D:/Projects/PC/Majorel_/Majorel_/Assets/Scripts/XML/Narrator/LoadXml_Narrator.cs Line: 20)
Note: IN the editor everything works perfect. The issue is only when build and execute the project.
Answer by Bund187 · Jul 19, 2018 at 05:46 PM
I found the origin of the problem. I had marked the checkbox: Scripts Only Build at Build Settings. Honestly, I don't know why becasue I didn't even know what it does. Anyway thank you so much for pointing me in the right direction. I Was about to go crazy.
After some research I found little info about this option, even the manual doesn´t show it https://docs.unity3d.com/Manual/BuildSettings.html The documentation just say: Build only the scripts of a project. So I guess it includes only some of the scripts for speed reasons when building.