I have a really simple extension method that I am calling from a MonoBehavior. When I use the method the Unity project fails to compile and states that the Behavior that is using the extension method can not be loaded, please fix compile errors and assign a valid script.
I’ve included the commented code in the behavior that works if I comment out the extension method call.
There are no errors in the Visual Studio project, and everything appears to be in order.
The extension class:
public static class TransformExtensions
{
public static void Clear(this Transform transform)
{
foreach (Transform child in transform)
{
Clear(child.transform);
GameObject.Destroy(child.gameObject);
}
GameObject.Destroy(transform.gameObject);
}
}
The behavior
public partial class MeasureManager : Singleton<MeasureManager>
{
void DeleteMeasurement(Measurement measurement)
{
//while (measurement.Container.transform.root.childCount > 0)
//{
// DestroyImmediate(measurement.Container.transform.root.GetChild(0).gameObject);
//}
//DestroyImmediate(measurement.Container.transform.gameObject);
measurement.Container.transform.Clear();
Measurements.Remove(Measurements.Find(x => x.Name == measurement.Name));
_current = null;
}
}