cannot convert from 'UnityEngine.Vector4' to 'float'

Hello. I am trying to convert a function from a shader to a C# script, but I have a problem with some convertion rules especially for some shapes. Cube and Hypercube works well, but these ones give me an error which I display in the title. What am I doing wrong ?

// Tetrahedron
        public float sdTetrahedron(float4 p, float a)
        {
            return (max(abs(p.x + p.y) - p.z, abs(p.x - p.y) + p.z) - a) / sqrt(3.0f);
        }
        // Octahedron
        public float sdOctahedron(float4 p, float a)
        {
            return (abs(p.x) + abs(p.y) + abs(p.z) - a) / 3;
        }

I don’t think the errors are here. Share the full error message (including line number) and the full script.

The error message points to these lines exactly…

But we have nothing showing us what you are passing into these methods. Giving us just the methods and nothing else is basically useless for anyone to help you.
Show us the exact error message (as has already been asked for), and the whole script so we can at least try to help.

Your first parameter is float4 p. I’m guessing that you are trying to pass a Vector4 as the first parameter. float4 and Vector4 are different types and it looks like you can’t implicitly cast one to another. Most likely you want to change your method to accept a Vector4 as the first parameter?

1 Like

They definitely don’t. It sound like you have an error when trying to call these methods somewhere. There is no mention of Vector4 anywhere in this code.

2 Likes

Solved. I had to convert correctly Vector4 to Float4. I cannot pass implicitly parameters. Thanks for help ++