S-C-A-N / SCANsat

Real Scanning, Real Science, at Warp Speed!
217 stars 97 forks source link

Invalid field initializers - Unity 5.x #243

Closed JPLRepo closed 7 years ago

JPLRepo commented 7 years ago

set_seed is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANskins' on game object 'SCANskins'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.Random:set_seed(Int32) SCANsat.SCAN_Platform.SCAN_MBE:.cctor() SCANsat.SCAN_UI.UI_Framework.SCANskins:.ctor() SCANsat.SCAN_UI.UI_Framework.SCANskins:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) AddonLoader:StartAddon(LoadedAssembly, Type, KSPAddon, Startup) AddonLoader:StartAddons(Startup) AddonLoader:OnLevelLoaded(Int32) AddonLoader:OnSceneLoaded(Scene, LoadSceneMode) UnityEngine.SceneManagement.SceneManager:Internal_SceneLoaded(Scene, LoadSceneMode) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\SceneManagerBindings.gen.cs:198)

set_left is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANkscMap' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.RectOffset:set_left(Int32) UnityEngine.RectOffset:.ctor(Int32, Int32, Int32, Int32) (at C:\buildslave\unity\build\Runtime\IMGUI\Managed\GUIStyle.cs:120) SCANsat.SCAN_Platform.SCAN_MBW:.ctor() SCANsat.SCAN_UI.SCANkscMap:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

set_left is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANsettingsUI' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.RectOffset:set_left(Int32) UnityEngine.RectOffset:.ctor(Int32, Int32, Int32, Int32) (at C:\buildslave\unity\build\Runtime\IMGUI\Managed\GUIStyle.cs:120) SCANsat.SCAN_Platform.SCAN_MBW:.ctor() SCANsat.SCAN_UI.SCANsettingsUI:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

set_left is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANcolorSelection' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.RectOffset:set_left(Int32) UnityEngine.RectOffset:.ctor(Int32, Int32, Int32, Int32) (at C:\buildslave\unity\build\Runtime\IMGUI\Managed\GUIStyle.cs:120) SCANsat.SCAN_Platform.SCAN_MBW:.ctor() SCANsat.SCAN_UI.SCANcolorSelection:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

set_left is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANresourceSettings' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.RectOffset:set_left(Int32) UnityEngine.RectOffset:.ctor(Int32, Int32, Int32, Int32) (at C:\buildslave\unity\build\Runtime\IMGUI\Managed\GUIStyle.cs:120) SCANsat.SCAN_Platform.SCAN_MBW:.ctor() SCANsat.SCAN_UI.SCANresourceSettings:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

nternal_Create is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANmainMap' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.Texture2D:Internal_Create(Texture2D, Int32, Int32, TextureFormat, Boolean, Boolean, IntPtr) UnityEngine.Texture2D:.ctor(Int32, Int32, TextureFormat, Boolean) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\TextureBindings.gen.cs:142) SCANsat.SCAN_UI.SCANmainMap:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

There are many many more.....

DMagic1 commented 7 years ago

Is this from log files? Or a crash dump?

JPLRepo commented 7 years ago

From the logs. It's a known thing with Unity 5. Sarbian posted about it a while back.

DMagic1 commented 7 years ago

Is this a Linux or OSX thing? I've never run into it. It's a good thing you caught this before I moved on to my other mods that use TriggerAu's framework, they all use these weird MonoBehaviour constructors.

Can you try this out? I moved all of the initialization to awake (and got rid of the out-dated Seed initializer). It is otherwise the same as 16.9.

https://www.dropbox.com/s/ocnq1yqpo4a1kco/SCANsat-v16.10-Test.zip?dl=0

JPLRepo commented 7 years ago

No they Still There. Perhaps I should explain a bit more. I am seeing them running the Development Mode Unity Exe. I believe they are only warnings from Unity and they intend to remove support for them. An Example:

In SCANsat.SCAN_Platform.SCAN_MBW You have defined:

internal RectOffset ClampToScreenOffset = new RectOffset(0, 0, 0, 0);

You have to define it as (in the ..ctor): internal RectOffset ClampToScreenOffset;

and then in Awake or Start you can create new: ClampToScreenOffset = new RectOffset(0, 0, 0, 0);

Here is Sarbian's post about it, which has a blog link in it: http://forum.kerbalspaceprogram.com/index.php?/topic/141400-some-advice-about-constructor-and-unity/#comment-2621140

See Script Serialization errors down the bottom of this page: https://docs.unity3d.com/Manual/script-Serialization.html

DMagic1 commented 7 years ago

Ahh, OK. How about now? I got rid of all the initial values and moved them to Awake if needed, even for the primitive types.

https://www.dropbox.com/s/7qq2jmo6gcjgh8y/SCANsat-v16.10-Test_2.zip?dl=0

JPLRepo commented 7 years ago

Yeah a lot are gone. Had this one still: Internal_Create is not allowed to be called from a MonoBehaviour constructor (or instance field initializer), call it in Awake or Start instead. Called from MonoBehaviour 'SCANmainMap' on game object 'ScenarioLogic'. See "Script Serialization" page in the Unity Manual for further details. UnityEngine.Texture2D:Internal_Create(Texture2D, Int32, Int32, TextureFormat, Boolean, Boolean, IntPtr) UnityEngine.Texture2D:.ctor(Int32, Int32, TextureFormat, Boolean) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\TextureBindings.gen.cs:142) SCANsat.SCAN_UI.SCANmainMap:.ctor() UnityEngine.GameObject:Internal_AddComponentWithType(Type) UnityEngine.GameObject:AddComponent(Type) (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:381) UnityEngine.GameObject:AddComponent() (at C:\buildslave\unity\build\artifacts\generated\common\runtime\UnityEngineGameObjectBindings.gen.cs:386) SCANsat.SCANcontroller:Start()

(I built a vessel with all the SCAN parts launched it, sent it up, did all the scans, etc) and only had the one above.

Primitives are ok. It's only where you call the Unity API in constructor.

DMagic1 commented 7 years ago

Once more: https://www.dropbox.com/s/06ellpphosq1jth/SCANsat-v16.10-Test_3.zip?dl=0

I think this should get them all. I moved out all of the initial values for any Unity elements from all of the windows and scripts that derive from MonoBehaviour. The only thing left is some static Rects, but those are used all over the place and would probably have shown up before if they were a problem.

And thanks for testing these.

JPLRepo commented 7 years ago

Looks good. Blizzy's toolbar has two of them (including the tool bar wrapper) lol. But the SCANsat one's themselves are all gone now.