EvilMindDevs / hms-unity-plugin

The HMS Unity Plugin makes it easy to include Huawei Mobile Services into Unity-based games. Authentication, in-app purchases, push alerts, ads, and interaction with gaming services are just a few of the basic capabilities that this formidable tool makes available to your applications.
https://evilminddevs.gitbook.io/hms-unity-plugin/
309 stars 44 forks source link

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

Open lxwgogogo opened 1 month ago

lxwgogogo commented 1 month ago

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?

github-actions[bot] commented 1 month ago

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:

lxwgogogo commented 1 month ago

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?

Andronovo-bit commented 1 month ago

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.

lxwgogogo commented 1 month ago

I am using 2022.3.14f1

Andronovo-bit commented 1 month ago

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.

qinhanlei commented 1 month ago

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.

amatveev commented 1 month ago

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)
.....
Andronovo-bit commented 1 month ago

@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.

amatveev commented 1 month ago

@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

qinhanlei commented 3 weeks ago

@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.

Andronovo-bit commented 3 weeks ago

@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