I receive the following error when trying to build my game using unity:
The name
AssetDatabase
does not exist in the current context
Can anyone please help.. I will appreciate all the help I can get..thank you
Build completed with a result of 'Failed' UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
UnityEditor.BuildPlayerWindow+BuildMethodException: 5 errors
at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (BuildPlayerOptions options) [0x0021f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:187
at UnityEditor.BuildPlayerWindow.CallBuildMethods (Boolean askForBuildLocation, BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:94 UnityEditor.BuildPlayerWindow:BuildPlayerAndRun()
It seems that in one of your scripts you use AssetDatabase
which belongs to the UnityEditor
namespace. It exists only inside the Unity Editor.
In a build the namespace UnityEditor
does not exists -> You can't use anything of it in a built application!
So after beeing aware of that there are basically to solutions how to fix those errors when using e.g. custom editor scripts or some code blocks that shall only exist inside of the Unity Editor but not in a build:
Either make sure all scripts that are only editor scripts are placed in folders called Editor
. Unity automatically excludes those in a build.
Or use the #if pre-processor with UNITY_EDITOR
:
#if UNITY_EDITOR
using UnityEditor;
#endif
...
#if UNITY_EDITOR
//some code here that uses something from the UnityEditor namespace
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With