Runtime Serialization layout differs from Edit-time

I’ve been busy for the last few weeks upgrading my codebase to work with Unity 2018.3. This included removing the now abandoned FullInspector asset and replacing it with the shiny new Odin asset.

Other than a few hitches and gotchas here and there things seemed to be going pretty smoothly so I decided to make a small game as a way to actually test everything. Things worked fine in the editor for the most part. However, the last two days have been a nightmare as I attempted to get the thing to build to a standalone for Windows. And once I finally got the build process working - bam - I’m hit with a mostly empty screen with a wall of errors all saying the same thing more-or-less.

“A scripted object (random script name here) has a different serialization layout when loading. Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?”

The answer to that query is yes, yes I did #ifdef some field and properties. It’s a perfectly sensible thing to do that has worked well in the past. Regardless of my feelings towards this message I decided to bite the bullet and remove the offending conditional compilations. To no avail. It appears absolutely every object that exists in the scene is puking this error at me, regardless of the non-existence of conditional compilation!

I thought perhaps Odin was the culprit somehow (despite not using its serialization features) but since it would have been impossible to remove it at this point I made a smaller project with just Odin and a few scripts. No such errors popped up in that case. I’m complete at a loss as to what I can do. I dunno how I can simplify the project while still effectively testing my own code. I don’t even know where to start in order to hunt down what might be the actual issue here.

Anyone else have these issues lately or ever for that matter? Any suggestions or clues that might help?

It only happened to me because I had the defines that remove some properties when built.
By default you don’t want to have anything that messes around with serialization, whether it’s define or not.

If you did have those defines, but removed them, try to update the serialized object. E.g. modifying some property and re-saving them.

They added an API during 2017 or so to do this:
https://docs.unity3d.com/ScriptReference/AssetDatabase.ForceReserializeAssets.html

2 Likes

Like I said before, I removed the conditional compilation on properties in order to ensure it wasn’t caused by them. Turns out it was the assembly definition files. On a whim I decided to delete all of them and everything worked just fine. Those asmdefs have been absolutely nothing but trouble for me. They need to be painstakenly setup for each Editor folder, slow down the iteration process to a crawl, and now this. I guess I could try to make some kind of build-process that temporarily removes them but it seems completely worthless for anything other than to confirm my code layers aren’t circular.

All the same, thanks for the tips.

3 Likes