Download

Select Float - Both A and B are evaluated?

Given this in an empty new project, in the level blueprint :

selectfloat1.jpg

I get a Divide by zero warning in the log, which means both A and B were evaluated, whereas only A should have been (or so would seem logical to me, at least).

aabfbd48844449a76fd8f38f55e8b7d6b39ec002.jpeg

An actual situation where MyArray == 1 :

b77c20f4cda27b5beb8b696508d40b3d7f9e141a.jpeg

It returns the divide by zero warning, but it shouldn’t?

It’s not a critical issue, but imagining A and/or B having a complex calculation, it seems like a waste of resources having both being evaluated if only one is necessary?

Is that intended or should it be reported as a bug?

Looking at the source code:

float UKismetMathLibrary::SelectFloat(float A, float B, bool bSelectA)
{
return bSelectA ? A : B;
}

To call this function, you have to send float A, float B, and the bSelectA, and then it returns the result. To send float A and B into the function, you must first evaluate them. So yes, this should be happening.

A compiler doesn’t know if only one is needed.
Your “select” boolean can be true or false at runtime.