Closed mwerle closed 5 years ago
Example exception from "output_log.txt":
UnityException: get_dataPath is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'ToolbarManager' on game object 'ToolbarManager'.
See "Script Serialization" page in the Unity Manual for further details.
at (wrapper managed-to-native) UnityEngine.Application:get_dataPath ()
at KSPUtil.get_ApplicationRootPath () [0x00000] in <filename unknown>:0
at Toolbar.ToolbarManager..cctor () [0x00000] in /var/lib/jenkins/workspace/G-L/ksp_toolbar/Toolbar/Internal/Toolbar/ToolbarManager.cs:35
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for Toolbar.ToolbarManager
PR #11 already addresses this issue
Ah, ok, nice one. I'll close this one then although our approach to fix DontDestroyOnLoad() is slightly different. I guess @linuxgurugamer can choose which one he prefers.
These Unity errors are pretty endemic throughout the KSP modding community though :( Almost every mod I take a look at has these issues. It's amazing most of it more or less actually seems to work.
I wonder if this used to work in earlier versions of Unity without the current issues? Anyway, thank you. I'm slowly finding other instances of this in various places. fixing as I go, anything you find is always appreciated
Unity APIs are not allowed to be called in field initializers or class constructors. Initialize your class in Awake() or Start() instead.
Tested with several mods which use the Toolbar and it seems to be working fine in both the released Unity player shipped with KSP 1.5 and the debug Unity player. No more exceptions in the debug player.