No announcement yet.

Select Float - Both A and B are evaluated?

  • Filter
  • Time
  • Show
Clear All
new posts

    Select Float - Both A and B are evaluated?

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

    Click image for larger version

Name:	selectfloat1.jpg
Views:	1
Size:	44.8 KB
ID:	1188223

    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).

    Click image for larger version

Name:	selectfloat2.jpg
Views:	1
Size:	33.0 KB
ID:	1188224

    An actual situation where MyArray == 1 :

    Click image for larger version

Name:	selectfloat3.jpg
Views:	1
Size:	80.8 KB
ID:	1188226

    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?
    Attached Files

    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.