Search Issue Tracker
By Design
Votes
0
Found in
2019.4
2019.4.18f1
2020.2
2021.1
2021.2
Issue ID
1309586
Regression
No
Unable to build different variable types on different Platforms
How to reproduce:
1. Open the attached "Android test.zip" Project
2. Try to build the Project on Android
3. Observe the Console
Expected Behavior: The build succeeds without errors
Actual Behavior: The build fails with an error
Reproducible with: 2019.4.19f1, 2020.2.3f1, 2021.1.0b3, 2020.2.0a2
Could not test with: .2018.4 due to assembly errors
Note:
- Build error: Type '[Assembly-CSharp]TestCode' has an extra field 'Health' of type 'System.Single' in the player and thus can't be serialized
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
Add comment
All about bugs
View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.
Latest issues
- Crash on GUIManager::DoGUIEvent when focusing on the Game view window on a specific project
- Asset creation in the Project Browser is not always undone/inconsistent when the undo shortcut is pressed right after creating an asset
- JobTempAlloc memory leak warning is thrown when the Player is shut down
- Graphics State Collection warm-up does not work when using with Addressables Shaders
- "Baked Shadow Radius" field is visible but inactive when when the Shadow Type is set to "Hard Shadows" under the Light Component
Resolution Note:
In your use case, in the editor the Property uses a different backing field for serialization and the intention is to access this data directly through a field at runtime to avoid extra check. This means that similarly to the Property you would need to initialize the value at runtime and would not need Serialization of the value. If the attribute [System.NonSerialized] is used against the field it will be present at runtime and accessible and will therefore not produce build errors as the serialization layout will be the same.
In attachment I have modified the code to demonstrate an initialization on Start. Another alternative would be to use ISerializationCallbackReceiver.OnAfterDeserialize to do this initialization at runtime. Unfortunately this will add a couple of bytes to your object at runtime. Though you would need to be cautious that those approach won't work if this code is called from a precompiled library.
Another alternative, is to make the property logic very minimal for runtime.