"Failed to load the HMSGameServiceSettings. Please restart Unity Editor." It happens in v2.3.8, worked in v2.3.7
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?
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:
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?
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.
I am using 2022.3.14f1
The Unity plugin has automatically created its own settings file in "Huawei > Settings > Resources."
Can you check again this folder ?
The plugin already won't use files that you copied in "Assets/Resources.". You can delete them.
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.
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 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 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)
@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.
@amatveev @qinhanlei
We tested this scenario in Unity 2022.3.40f1, but we did not receive any errors similar to yours.
-
You should never modify the settings file manually. This file has a format.
-
If you have rarely encountered this error, you can;
- Go to Assets > Reimport All in the Unity Editor.
-
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.
-
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
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.
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;
}
}
}
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" };