• Register
3,890 points
11 5 1
Welcome to Kodlogs, programming questions and answer website.

Before using any Unity API, its very important for users to check the API namespace. If the namespace is from UnityEditor then it will work only in this editor. The users can not use it in a build and this will throw an error while building from any other platform.  According to docs, AssetDatabase and EditorUtility classes are from UnityEditor namespace.

You have to redesign your game to work without any GetAssetPath function. The game can be developed without using that function. This will help you to load your Game objects during run time.

Solution:

To solve your current problem;

Replace

using UnityEditor

with

#if UNITY_EDITOR

using UnityEditor;

#endif

After this replace

objMaterial.textureName = EditorUtility.GetAssetPath(mats[material].mainTexture);

with

objMaterial.textureName = “”;

#if UNITY_EDITOR

objMaterial.textureName = EditorUtility.GetAssetPath(mats[material].mainTexture);

#endif

Note:

The user can also put their menu script in the folder Assets/Editor directly But you have to understand that this cannot solve your problem and your code won’t work in a built. This will only allow your project to built without these errors in your questions. These classes are from the UnityEditor namespace can only used for Editor Plugin.

3,890 points
11 5 1