Search Issue Tracker

Fixed in 2017.3.0f3

Fixed in 2017.2.X

Votes

0

Found in

5.6.0f3

Issue ID

918102

Regression

No

[.NET] const field named same as a field in base class causes the field in base class to not get serialized

Repro consists of 2 classes:

using UnityEngine;

abstract class BaseClass : MonoBehaviour
{
[SerializeField]
private int m_Number = 5;

public void LogNumber()
{
Debug.Log(m_Number);
}
}

class DerivedClass : BaseClass
{
private const int m_Number = 56;

private void Awake()
{
Debug.Log(m_Number);
LogNumber();
}
}

Drag DerivedClass onto main camera, and set "m_Number" field to 22 in the inspector. Hit play in the editor and observe the following output:

56
22

Now, build to Windows Store .NET scripting backend. Run it, and observe this output:

A script behaviour (probably DerivedClass?) has a different serialization layout when loading. (Read 32 bytes but expected 36 bytes)
Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

(Filename: D:\Projects\unity\Runtime/Serialize/SerializedFile.cpp Line: 1895)

56
5

Add comment

Log in to post comment

All about bugs

View bugs we have successfully reproduced, and vote for the bugs you want to see fixed most urgently.