Ran into a bug I think is caused by the new expiremental .NET 4.6 runtime in Unity 2017.1. I submitted the following bug report to Unity:
I opted to make use of the new Experimental .NET 4.6 Runtime in 2017.1 and started running into an issue. From everything I have gathered, there is an issue with (at least) variables of type bool/System.Boolean being passed in to a method with a signature that accepts object/System.Object and the bool value (at least for false) is being changed into an object value of null, which is not correct.
See the attached image taken from Visual Studio 2017 C# Interactive window to prove the proper/expected behavior (which also worked in Unity .NET 3.5 runtime).
image?
So, I went to create a simple Unity 2017.1 project that uses the experimental .NET 4.6 runtime to demonstrate the issue I (think) am seeing in a larger project…and the below code does the right things and does not corroborate my initial finding. Will continue to dig deeper and report back.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BoolToObjectTest : MonoBehaviour
{
public bool ThisIsABoolField;
void Start()
{
Debug.Log("Hello there. Inside MonoBehaviour method. Here is the value of ThisIsABoolField: " + ThisIsABoolField);
OutputToDebugWindow(ThisIsABoolField);
var nonUnity = new NonUnityClass();
nonUnity.OutputToDebugWindow(false);
nonUnity.OutputToDebugWindow(true);
bool someLocalBool = false;
nonUnity.OutputToDebugWindow(someLocalBool);
someLocalBool = true;
nonUnity.OutputToDebugWindow(someLocalBool);
}
void OutputToDebugWindow(object thisIsAnObjectParameter)
{
Debug.Log("Hello there. Inside MonoBehaviour method. Here is the value of thisIsAnObjectParameter: " + thisIsAnObjectParameter);
}
}
public class NonUnityClass
{
public bool ThisIsABoolField;
public NonUnityClass()
{
Debug.Log("Hello there. Inside external class method. Here is the value of ThisIsABoolField: " + ThisIsABoolField);
OutputToDebugWindow(ThisIsABoolField);
}
public void OutputToDebugWindow(object thisIsAnObjectParameter)
{
Debug.Log("Hello there. Inside external class method. Here is the value of thisIsAnObjectParameter: " + thisIsAnObjectParameter);
}
}