flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
get_dataPath is not allowed to be called from a ScriptableObject constructor
Describe the bug I followed the steps to install the script but on compile I get the following error in Unity's console:
UnityException: get_dataPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'Build'.
See "Script Serialization" page in the Unity Manual for further details.
Build..cctor () (at Assets/FlutterUnityIntegration/Editor/Build.cs:12)
Rethrow as TypeInitializationException: The type initializer for 'Build' threw an exception.
To Reproduce Steps to reproduce the behavior:
- Install script on Unity 2020.3.19f1
- Open console and read log
- Flutter export to iOS/Android is present in the menu but does nothing
Expected behavior The script should compile. The menu options should work.
Unity (please complete the following information):
- macOS 12.1, M1
- 2020.3.19f1
- Note: I tried installing the script in latest LTS (2020.3.26f1) and it never shows in the menu.
Additional context Defining these properties as writable statics works:
public class Build : EditorWindow
{
// Define and set later on OnEnable
static string ProjectPath = "";
static string apkPath = "";
static string androidExportPath = "";
static string iosExportPath = "";
static string iosExportPluginPath = "";
// ...
And then assigning values in OnEnable() (note: error is still displayed in the console):
private void OnEnable()
{
// Assign value OnEnable to avoid error
// UnityException: get_dataPath is not allowed to be called from a ScriptableObject constructor (or instance field initializer), call it in OnEnable instead. Called from ScriptableObject 'Build'.
ProjectPath = Path.GetFullPath(Path.Combine(Application.dataPath, ".."));
apkPath = Path.Combine(ProjectPath, "Builds/" + Application.productName + ".apk");
androidExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../android/unityLibrary"));
iosExportPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios/UnityLibrary"));
iosExportPluginPath = Path.GetFullPath(Path.Combine(ProjectPath, "../../ios_xcode/UnityLibrary"));
pluginMode = EditorPrefs.GetBool(persistentKey, false);
}
Now it exports to ../../ios/unity/ apparently correct.
I also had to change AcceptExternalModificationsToPlayer
to AllowDebugging
. I may open a different issue for that.
If you need anything else, please let me know. Thanks.
@juicycleff We are very interested in using this in our project. We want to make an Android/iOS app with a Unity component, so this could be useful. I'm having quite a few issues getting it to run though, latest LTS does not even load the script.
I forgot to mention that you have to open the plugin window first (Flutter-> Settings) or else the export will not work. I think the OnEnable part is not initialized if you don't do this.
This is the error:
ArgumentException: The 'locationPathName' parameter for BuildPipeline.BuildPlayer should not be null or empty.
UnityEditor.BuildPipeline.BuildPlayer (System.String[] scenes, System.String locationPathName, System.String assetBundleManifestPath, UnityEditor.BuildTargetGroup buildTargetGroup, UnityEditor.BuildTarget target, UnityEditor.BuildOptions options, System.String[] extraScriptingDefines) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline.bindings.cs:329)
UnityEditor.BuildPipeline.BuildPlayer (UnityEditor.BuildPlayerOptions buildPlayerOptions) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline.bindings.cs:295)
UnityEditor.BuildPipeline.BuildPlayer (System.String[] levels, System.String locationPathName, UnityEditor.BuildTarget target, UnityEditor.BuildOptions options) (at /Users/bokken/buildslave/unity/build/Editor/Mono/BuildPipeline.bindings.cs:290)
Build.BuildIOS (System.String path) (at Assets/FlutterUnityIntegration/Editor/Build.cs:160)
Build.DoBuildIOS () (at Assets/FlutterUnityIntegration/Editor/Build.cs:102)
Closing this as outdated. This looks specific to older unitypackages, probably in the 4.x range.