We ran into this issue exclusively when we were on the Android platform in the editor. In our case we couldn't just remove the Curvy Global instance (it kept coming back).
But looking into it, I think we've figured out where this bug comes from. In 2017.2, Unity changed it so that
From: https://docs.unity3d.com/2017.2/Documentation/Manual/UpgradeGuide20172.html
The setter in ComponentPool.cs assumes the value you pass in is not null
However, it also has a OnValidate method
And this component is created dynamically in PoolManager.CreateComponentPool
And in this code, the component is created in AddComponent with a null value for m_Settings, because the settings are only passed in through the subsequent Initialize call. However, in 2017.2, the AddComponent will call OnValidate, which will set the Settings property to the null value, which has no null check.
So we fixed it by adding a null check in the setter:
But looking into it, I think we've figured out where this bug comes from. In 2017.2, Unity changed it so that
Quote:MonoBehaviour.OnValidate is now called when MonoBehaviour is added to a GameObject in the Editor
From: https://docs.unity3d.com/2017.2/Documentation/Manual/UpgradeGuide20172.html
The setter in ComponentPool.cs assumes the value you pass in is not null
Code:
public PoolSettings Settings
{
get { return m_Settings; }
set
{
Debug.Log(this.gameObject.scene.name);
if (m_Settings != value)
m_Settings = value;
m_Settings.OnValidate();
}
}
However, it also has a OnValidate method
Code:
void OnValidate()
{
Settings = m_Settings;
}
And this component is created dynamically in PoolManager.CreateComponentPool
Code:
if (!Pools.TryGetValue(typeof(T).AssemblyQualifiedName, out res))
{
res = gameObject.AddComponent<ComponentPool>();
((ComponentPool)res).Initialize(typeof(T),s);
Pools.Add(res.Identifier, res);
}
And in this code, the component is created in AddComponent with a null value for m_Settings, because the settings are only passed in through the subsequent Initialize call. However, in 2017.2, the AddComponent will call OnValidate, which will set the Settings property to the null value, which has no null check.
So we fixed it by adding a null check in the setter:
Code:
public PoolSettings Settings
{
get { return m_Settings; }
set
{
Debug.Log(this.gameObject.scene.name);
if (m_Settings != value)
m_Settings = value;
if(m_Settings != null)
{
m_Settings.OnValidate();
}
}