Getting errors from BuildPipeline.BuildAssetBundles but not when building game...
I have looked at a number of threads about errors between editor and production builds related to AssetBundles:
https://answers.unity.com/questions/316805/unityeditor-namespace-not-found.html?_ga=2.189548139.1946127219.1585938144-183802302.1574265257 https://forum.unity.com/threads/scripts-in-editor-folders-throwing-build-errors-when-building-assetbundles-for-mobile.482755/ They do not seem to relate to the issue I am having. I can do in editor builds of the game for Android, iOS, and WebGL and they run in the editor.
But, when I call the BuildPipeline.BuildAssetBundles API the Photon 3rd party library gives a bunch of errors like this one:
Yet the code looks very straight forward:
using UnityEditor;
using UnityEngine;
[InitializeOnLoad]
public class ChatEditor : EditorWindow
It is the class declaration is line 21 that is showing the error.
It seems like maybe there is some compiler defines set that are different when the BuildPipeline.BuildAssetBundles is called as compared to what is set during editor builds?
Any ideas? It is a major stumbling block for me right now.
There is an update to the Photon Library that I am going to pull in next but I don't have a lot of confidence that will fix it. The current code that is showing the error looks pretty good.
Answer by griderd · Jun 12, 2020 at 10:00 AM
It's a crappy solution, but you need to wrap any classes giving you that error in
#if UNITY_EDITOR
using Foo;
public class Bar
{
// code here
}
#endif
I'm not entirely sure why, but the BuildAssetBundles() function wants to build stuff inside Editor folders as if they're supposed to run in the game.
Your answer
Follow this Question
Related Questions
Unity Scripts Working Fine in Editor, But not in Build 0 Answers
How to change the project's Splash Image in a build? 0 Answers
Realtime Lighting Does Not work in Build (Unity 2018.4.18) 0 Answers
GameObject doesn't load ammocounter prefab from FPS microgame (Unity 2018.4.18) 0 Answers
Unity Editor crashes when pressing play (2017.2.0f3 64bit) 2 Answers