I need help with Assertion failed on expression: 'CompareApproximately(SqrMagnitude(result), 1.0F)' UnityEngine.Quaternion:Euler(Single, Single, Single) error

I need help with an Assertion failed on expression: ‘CompareApproximately(SqrMagnitude(result), 1.0F)’
UnityEngine.Quaternion:Euler(Single, Single, Single) error so my trees will spawn.

This is my TreeSpawn class

public class TreeSpawn : MonoBehaviour
{
    public GameObject functions;
    public GameObject treeObject;
    public PolygonCollider2D polyCollider;
    public float moveInctrement;
    public float minSpawnAngle;
    public float maxSpawnAngle;

    // Start is called before the first frame update
    void Start()
    {
        var functionsScript = functions.GetComponent<CustomFunctions>();
        Vector2[] colliderPoints = polyCollider.points;
        float[] colliderPointsX = new float[colliderPoints.Length];
        float[] colliderPointsY = new float[colliderPoints.Length];
        int numPoints = colliderPoints.Length;
        
        for (int i = 0; i < numPoints; i++)
        {
            colliderPointsX _= colliderPoints*.x;*_

}

for (int i = 0; i < numPoints; i++)
{
colliderPointsY = colliderPoints*.y;*
}

MoveTo(Mathf.Min(colliderPointsX), Mathf.Max(colliderPointsY) + 1f, 0f);

for (float x = 0; x < Mathf.Max(colliderPointsX); x += moveInctrement)
{
RaycastHit2D hit = Physics2D.Raycast(transform.position, Vector2.down);
Ray2D ray = new Ray2D(transform.position, Vector2.down);

if (Physics2D.Raycast(ray.origin, ray.direction))
{

float[] colliderPointsDistance = new float[colliderPoints.Length];
for (int i = 0; i < colliderPoints.Length; i++)
{
functionsScript.CalcRightAngleTriangle(colliderPoints*, hit.point, out float angle1, out float length1);*
colliderPointsDistance = length1;
}

functionsScript.CalcRightAngleTriangle(colliderPoints[GetIndexOfLowestValue(colliderPointsDistance)], colliderPoints[GetIndexOfSecondLowestValue(colliderPointsDistance)], out float angle2, out float length2);

if (angle2 > minSpawnAngle && angle2 < minSpawnAngle)
{
var instantiateAngle = Quaternion.Euler(0f, 0f, angle2);
Instantiate(treeObject, hit.point, instantiateAngle);
}

}
}
}

void MoveTo(float x, float y, float z)
{
Vector3 destination = new Vector3(x, y, z);
transform.position = destination;
}

public int GetIndexOfLowestValue(float[] arr)
{
float value = float.PositiveInfinity;
int index = -1;
for (int i = 0; i < arr.Length; i++)
{
if (arr < value)
{
index = i;
value = arr*;*
}
}
return index;
}

public int GetIndexOfSecondLowestValue(float[] arr)
{
int smallest = GetIndexOfLowestValue(arr);

float value = float.PositiveInfinity;
int index = -1;
for (int i = 0; i < arr.Length; i++)
{
if (arr < value && i != smallest)
{
index = i;
value = arr*;*
}
}
return index;
}
}
This is my editor
[164557-ed-1.png|164557]

Help is enormously appreciated!

Hey! I was having this same error message earlier. It turns out one of the variables I was passing to Quaternion.Euler() was being divided by zero. Check if that’s not happening to angle2 before reaching line 51 on your code.