Type has an extra field of type in the player and thus can't be serialized error

I’m getting intermittent errors on our build machine due to serialization issues. It’s strange that it only seems to happen on Android builds on our Windows build machine (not iOS builds on our macOS build machine). It occurs when we build AssetBundles to save into StreamingAssets folder of the binary. The error looks like this:

Type ‘[Assembly-CSharp]DungeonCrawler.Client.PVPHubPopup’ has an extra field ‘rewardProgressLabel’ of type ‘TMPro.TextMeshProUGUI’ in the player and thus can’t be serialized (expected ‘attackLogTabButton’ of type ‘UnityEngine.UI.Button’)

Fields serialized in Editor, class ‘DungeonCrawler.Client.PVPHubPopup’
‘playerNameLabel’ of type ‘TMPro.TextMeshProUGUI’
‘playerLevelLabel’ of type ‘TMPro.TextMeshProUGUI’
‘playerRankingLabel’ of type ‘TMPro.TextMeshProUGUI’
‘attackLogTabButton’ of type ‘UnityEngine.UI.Button’
‘defenseLogTabButton’ of type ‘UnityEngine.UI.Button’
‘battleLogContainer’ of type ‘UnityEngine.Transform’
‘battleLogEntryPrefab’ of type ‘UnityEngine.GameObject’

Fields serialized in target platform, class ‘DungeonCrawler.Client.PVPHubPopup’
‘playerNameLabel’ of type ‘TMPro.TextMeshProUGUI’
‘playerLevelLabel’ of type ‘TMPro.TextMeshProUGUI’
‘playerRankingLabel’ of type ‘TMPro.TextMeshProUGUI’
‘rewardProgressLabel’ of type ‘TMPro.TextMeshProUGUI’
‘attackLogTabButton’ of type ‘UnityEngine.UI.Button’
‘defenseLogTabButton’ of type ‘UnityEngine.UI.Button’
‘battleLogContainer’ of type ‘UnityEngine.Transform’
‘battleLogEntryPrefab’ of type ‘UnityEngine.GameObject’

I’ve searched the forums and beyond (Stack Overflow, etc.) for answers but none of them seem to apply to us. Specifically:

  • We do not use partial classes;
  • We do not have serialized fields inside preprocessor directives;
  • We set the “-buildTarget android” flag on each invocation of the build

The files complained about are also different – it’s not always the same file. I’ve tried removing the Library folder on the build machine to no avail. Is there something weird with the way
BuildPipeline.BuildAssetBundles() works? We’re just passing in the StreamingAssets directory, ChunkBasedCompression as an option, and BuildTarget.Android as the target.

Re-running the build after the failure will put the build back into the correct state, but I’m not sure what system is getting put into an incorrect state in the first place.

Any ideas? I’d like to file a bug but it’s tough to reproduce because it relies not only on our project but also our Jenkins build machine and its job configuration.

1 Like

Hello, same error here, I built the game yesterday, but after some improvements today, everything that I changed now comes with this msg on build…

1 Like

I’m running into this same issue now — trying to build Android (for Quest) from macOS. Unity 2019.3 doesn’t seem to support copying console messages as text, but here’s a screenshot:

This makes no sense to me. Since when is a TextMeshProUGUI reference not serializable?

Ugh… yes, it appears to be an intermittent Unity bug. After running in the editor, then I was able to build. Sheesh.

3 Likes

This worked for me, thank you!

This bug still exists in 2019.3.9 Tried many times with no luck. The error message was pointing an enum that was in a class. I moved that enum out of the class. Tried again and it worked, it built successfully. Then I reverted that changed and moved the enum back in class. It built successfully again! Note: Build target : Windows x86_64

Hey what do you mean by running in the editor?

1 Like

just remove the unity UI package and install it again

This is still present in unity 2022.1.20 and extremely irritating to work around.

2 Likes

I’m seeing this, too.

I’m seeing this too in 2022.1.17f1, just added a bool in the class, then I’m unable to sterilize asset bundle

I have resolved this issue by deleting ‘Library/Bee’ and ‘Library/BuildPlayerData’ folders before run build script.
(in Unity 2022.1.14)

15 Likes

it work!!!

This is the best solution, thank you so much

Thanks it worked (2022.2.0f).

Getting this error in Unity 2022.2.6f1
Tried the following, which did not work:

  • Deleting Bee and BuildPlayerData
  • Deleting Library
  • Reimport All
  • Reinstalling Editor

I don’t know what to do from here.

1 Like

I have similar issues using Unity 2022.2.6f1. There are no issues when building asset bundles from GUI but from command line weird errors occur. Deleting Bee and BuildPlayerData causes the entire command line build to fail (GUI builds are still working)

Any news on this? I have this issue too and it completely breaks our automated builds

Yep that was it! How truly obscure…

I feel this might be a bug, but for some reason, there isn’t clear information confirming whether this is indeed a bug or not. As a temporary solution, I managed to resolve the issue by deleting the ‘Library/Bee’ and ‘Library/BuildPlayerData’ directories. This approach worked for me