# Error converting singles and floats

I have a custom data type I made called a point.

It has implicit operators to easily convert between a Vector3 and a float[], the reason being Vector3 and Vector2 types are not System.Serializable meaning they cant be converted to binary, before I would use a simple method like this:

public static void Vector3ToFloatArray(Vector3 v)
{
return new float[] {v.x, v.y, v.z};
}


And another for float[] to Vector3

Here is the code I made for my custom point data type:

using System;
using UnityEngine;

[Serializable]
public struct Point {
public float x, y, z;

public Point(float x, float y, float z)
{
this.x = x;
this.y = y;
this.z = z;
}

public static implicit operator Vector3(Point p) => new(p.x, p.y, p.z);

public static implicit operator float[](Point p) => new float[] {p.x, p.y, p.z};

public static implicit operator Point(Vector3 v) => new(v.x, v.y, v.z);

public static implicit operator Point(float[] f)
{
if (f.Length != 3) throw new ArgumentException("Float array must have exactly 3 elements for point conversion.");
return new Point(f[0], f[1], f[2]);
}

public bool IsZero
{
get {
if (x == 0 && y == 0 && z == 0) return true;
return false;
}
}
}


As you can see I have an operator for converting from Point to float array and the other way around. Yet in Unity it says:

It claims a Single[] can't be converted into a 'Point' even though I have the implicit operator in place.

The 'position' variable it's referring to is inside my SaveData script:

using UnityEngine;

namespace Game.Save
{
[System.Serializable]
public class SaveData
{
public int MusicIndex { get; set; } = 0;
public Point position;

// TEMPORARY
public SaveData(Vector3 pos, int musicDex)
{
position = pos;
}
}
}


As you can see inside the constructer I'm able to set position to a Vector3 due to that implicit operator, so I should be able to convert a float array into it and I don't understand why it's throwing this error.

Edit: I forgot to mention the reason the error is for "point" and the struct is called "Point" is because after the error threw I also did some code optimization like making point capitalized. The new error looks like this:

• It says point with a lower case "p". Your struct has an upper case "P". Note that C# is case sensitive. Is there another type called point somewhere? Or maybe you renamed it and there is still an older version stored somewhere? Feb 8 at 16:33
• I have just updated my question with a small explanation on that.
– Pow
Feb 8 at 16:38
• Can you set a breakpoint in implicit operator Point(float[] f) to see whether it is called and then single step throught it? And also a breakpoint where you think this conversion is called. Feb 8 at 16:47
• Sorry I've missed a part out again, the conversion works fine, its just I serialize the data to a file and the error occurs in this Line when trying to deserialize the file back into a SaveSlot SaveSlot slotResult = formatter.Deserialize(slotStream) as SaveSlot; the 'SaveSlot' contains a 'SaveData', which contains the 'position' Point variable.
– Pow
Feb 8 at 17:00
• Bear in mind that you'll get a garbage collector allocation every time that implicit operator is triggered and produces an array. Do you need to convert to an array, or would it suffice to implement the [] operator? (Or rely on implicit conversion to Vector3 to lean on its implementation?) Feb 8 at 17:26