hms-unity-plugin icon indicating copy to clipboard operation
hms-unity-plugin copied to clipboard

"Failed to load the HMSGameServiceSettings. Please restart Unity Editor." It happens in v2.3.8, worked in v2.3.7

Open lxwgogogo opened this issue 1 year ago • 11 comments

Describe the bug & problem The v2.3.7 works well on my phone. But after I upgrade to v2.3.8, it throws error:

A scripted object (script unknown or not yet loaded) has a different serialization layout when loading. (Read 56 bytes but expected 64 bytes)
Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

I debugged and found the ScriptableHelper.Load has var asset = Resources.Load<T>(filename); which the asset is null. I wonder if I should copy the Assets/Huawei/Settings/Resources folder to my Assets/Resources folder?

lxwgogogo avatar Jul 17 '24 02:07 lxwgogogo

Thank you for reporting this issue/advice.

We will get back to you as soon as possible.
Would you like to star our plugin to support us? :sparkles:

github-actions[bot] avatar Jul 17 '24 02:07 github-actions[bot]

Let me answer to myself. After I copy the Assets/Huawei/Settings/Resources folder to my Assets/Resources folder?, now it works. Is this a required step after the upgrade to v2.3.8?

lxwgogogo avatar Jul 17 '24 03:07 lxwgogogo

Hello, @lxwgogogo , We tried the game service and didn't faced any errors like the ones you're getting with the settings.

Actually setting's file path is right. It needs to be in Huawei > Settings > Resources.

Maybe, this error is one shot. Can you tell us which Unity version you are using?

Just try this; Rollback last changes that about settings path and then make Assets > Import All in Unity. Open again and run your project.

Andronovo-bit avatar Jul 17 '24 06:07 Andronovo-bit

I am using 2022.3.14f1

lxwgogogo avatar Jul 18 '24 01:07 lxwgogogo

The Unity plugin has automatically created its own settings file in "Huawei > Settings > Resources."

image

Can you check again this folder ?

The plugin already won't use files that you copied in "Assets/Resources.". You can delete them.

Andronovo-bit avatar Jul 18 '24 07:07 Andronovo-bit

I also encountered this issue once. When I ran git clean -fdx in my project and then reopened Unity 2022.3.39f1, the issue disappeared. Still don't know why.

qinhanlei avatar Aug 02 '24 13:08 qinhanlei

i have same error in android build Unity 2022.3.39f1

A scripted object (script unknown or not yet loaded) has a different serialization layout when loading. (Read 52 bytes but expected 60 bytes)
Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

UnityEngine.Resources:Load(String)
HmsPlugin.ScriptableHelper:Load(String, String)
HmsPlugin.HMSIAPKitSettings:.ctor()
System.Activator:CreateInstance()
HmsPlugin.HMSEditorSingleton`1:get_Instance()
HmsPlugin.HMSIAPManager:InitControlOfIAP()
HuaweiMobileServices.Utils.HMSDispatcher:InvokeAsync(Action)
System.Lazy`1:CreateValue()
Gameplay.Billing.Factories.Android.Huawei.ControllerFactory:Create(IAuthTokenSource, IGame, BillingEvents, CurrencyConverter)
.....

amatveev avatar Aug 02 '24 13:08 amatveev

@amatveev Can you try other Unity version ?

We tried 2022.3.18f1, and we didn't face any errors that you faced.

In the meantime, we will try the Unity version that you used. After that, let's we compare results together.

Andronovo-bit avatar Aug 02 '24 14:08 Andronovo-bit

@amatveev Can you try other Unity version ?

We tried 2022.3.18f1, and we didn't face any errors that you faced.

In the meantime, we will try the Unity version that you used. After that, let's we compare results together.

We upgrade project from 2020.3.41f1 to 2022.3.39f1. After unity editor upgrade we are upgrade hms-unity-plugin 2.3.4 -> 2.3.8 and 2.3.8 + 2020.3.41f1 work fine

summary: 2.3.8 + 2020.3.41f1 - ok 2.3.8 + 2022.3.39f1 - error 2.3.8 + 2022.3.40f1 - error

A scripted object (script unknown or not yet loaded) has a different serialization layout when loading. (Read 52 bytes but expected 60 bytes)
Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

UnityEngine.Resources:Load(String)
HmsPlugin.ScriptableHelper:Load(String, String)
HmsPlugin.HMSIAPKitSettings:.ctor()
System.Activator:CreateInstance()
HmsPlugin.HMSEditorSingleton`1:get_Instance()
HmsPlugin.HMSIAPManager:InitControlOfIAP()
HuaweiMobileServices.Utils.HMSDispatcher:InvokeAsync(Action)
System.Lazy`1:CreateValue()
Gameplay.Billing.Factories.Android.Huawei.ControllerFactory:Create(IAuthTokenSource, IGame, BillingEvents, CurrencyConverter)

hms-unity-p-2 3 8

amatveev avatar Aug 02 '24 14:08 amatveev

@Andronovo-bit @amatveev I encountered this issue again. Our project uses version 2022.3.39f1, and the issue disappears upon restarting Unity. It seems to be a bug in Unity that occurs when something is cached during multiple builds.

qinhanlei avatar Aug 07 '24 06:08 qinhanlei

@amatveev @qinhanlei

We tested this scenario in Unity 2022.3.40f1, but we did not receive any errors similar to yours.

  1. You should never modify the settings file manually. This file has a format.

  2. If you have rarely encountered this error, you can;

    • Go to Assets > Reimport All in the Unity Editor.
  3. If second solution don't solve your problem, you can;

    • Close Unity.
    • Delete the Library folder in your project directory (this folder will be recreated when you reopen the project).
    • Reopen Unity and let it recompile everything.
  4. As a final step, if your problem persists, could you replace the following code in the ScriptableHelper.cs file?


Could you send the HMSIAPKitSettings.asset file that causes an error in Settings/Resources? @amatveev

Andronovo-bit avatar Aug 07 '24 08:08 Andronovo-bit

Thank you for using our repository! We're glad we could help solve your issue. If you found our repository helpful, please consider giving us a star ⭐ on GitHub: https://github.com/EvilMindDevs/hms-unity-plugin

Your support helps us continue to improve our repository and provide valuable resources for others.

github-actions[bot] avatar Nov 04 '24 06:11 github-actions[bot]

I solved the problem in the following way. In my case, there were no settings in this file and you can do it like this.

using System; using UnityEngine;

namespace HmsPlugin
{
    public class HMSIAPKitSettings : HMSEditorSingleton<HMSIAPKitSettings>
    {
        private const string SettingsFilename = "HMSIAPKitSettings";
        public const string InitializeOnStart = "InitializeOnStart";
        public const string ConsumptionOwnedItemsOnInitialize = "ConsumptionOwnedItemsOnInitialize";
        private SettingsScriptableObject loadedSettings;

        private HMSSettings _settings;
        public HMSSettings Settings => _settings;

        public HMSIAPKitSettings()
        {
            loadedSettings = ScriptableObject.CreateInstance<SettingsScriptableObject>();
            //loadedSettings = ScriptableHelper.Load<SettingsScriptableObject>(SettingsFilename, "Assets/Huawei/Settings/Resources");
            if (loadedSettings == null)
            {
                throw new InvalidOperationException($"Failed to load the {SettingsFilename}. Please restart Unity Editor");
            }
            _settings = loadedSettings.settings;
            _settings.OnDictionaryChanged += _settings_OnDictionaryChanged;
        }

        private void _settings_OnDictionaryChanged()
        {
            loadedSettings.Save();
        }

        public void Reset()
        {
            _settings.Dispose();
            _instance = null;
        }
    }
}

PavelPerelygin avatar May 21 '25 14:05 PavelPerelygin

For me the errors came because in HMSEditorUtils, HuaweiMobileServices.Core.asmdef is set to have the Editor value. This is my fix:

//coreAssemblyDefinition.includePlatforms = enable ? new List<string> { "Editor", "Android" } : new List<string> { "Editor" };
coreAssemblyDefinition.includePlatforms = enable ? new List<string>() : new List<string> { "Editor" };

flashmandv avatar Oct 15 '25 07:10 flashmandv