Unexpected float in Custom Function

I am running into this issue and have not been able to resolve it for hours.

"syntax error: unexpected float constant at line 199"

Here is the Generated code: Line 199 starts at the comment

// unity-custom-func-begin
void WaveHeight_float(float2 worldXZ, float time, float amp1, float2 dir1, float wl1, float spd1, float amp2, float2 dir2, float wl2, float spd2, float amp3, float2 dir3, float wl3, float spd3, out float height)
{
const float TWO_PI = 6.2831853;
float h = 0;

float k1 = TWO_PI / max(wl1, 0.001);
float k2 = TWO_PI / max(wl2, 0.001);
float k3 = TWO_PI / max(wl3, 0.001);

dir1 = normalize(length(dir1) < 1e-5 ? float2(1,0) : dir1);
dir2 = normalize(length(dir2) < 1e-5 ? float2(0,1) : dir2);
dir3 = normalize(length(dir3) < 1e-5 ? float2(-1,0) : dir3);

float p1 = dot(worldXZ, dir1) * k1 + spd1 * time;
float p2 = dot(worldXZ, dir2) * k2 + spd2 * time;
float p3 = dot(worldXZ, dir3) * k3 + spd3 * time;

h += amp1 * sin(p1);
h += amp2 * sin(p2);
h += amp3 * sin(p3);

height = h;
}
// unity-custom-func-end

Custom Function:

Type: String
Name: WaveHeight
Body:

const float TWO_PI = 6.2831853;
float h = 0;
float k1 = TWO_PI / max(wl1, 0.001);
float k2 = TWO_PI / max(wl2, 0.001);
float k3 = TWO_PI / max(wl3, 0.001);

dir1 = normalize(length(dir1) < 1e-5 ? float2(1,0) : dir1);
dir2 = normalize(length(dir2) < 1e-5 ? float2(0,1) : dir2);
dir3 = normalize(length(dir3) < 1e-5 ? float2(-1,0) : dir3);

float p1 = dot(worldXZ, dir1) * k1 + spd1 * time;
float p2 = dot(worldXZ, dir2) * k2 + spd2 * time;
float p3 = dot(worldXZ, dir3) * k3 + spd3 * time;

h += amp1 * sin(p1);
h += amp2 * sin(p2);
h += amp3 * sin(p3);

height = h;

Inputs:
worldXZ (Vector2)
time (Float)
amp1 (Float)
dir1 (Vector2)
wl1 (Float)
spd1 (Float)
amp2 (Float)
dir2 (Vector2)
wl2 (Float)
spd2 (Float)
amp3 (Float)
dir3 (Vector2)
wl3 (Float)
spd3 (Float)

Outputs:
height (Float)

this would be much easier to solve in an IDE where the line numbers are shown (or use the code formatting for all of it!!!) but i will say that often when the errors involve unexpected variables, it is not due to the line marked (#199) being wrong, but the one right before it never closing a parentheses or using incorrect variable types in a function. hope this helps.

Thanks.

I ended up solving this as the “const float TWO_PI = 6.2831853;” was causing the issue.

I ended up having to create a property called TWP_PI and set the value to 6.2831853, and then removing the “const float TWO_PI = 6.2831853;” from the custom function.

This allowed it to be defined outside the function and the custom node function could refer to that variable.

TWO_PI is pre-defined in unity shader library. You can use it without definition.