Is there any way to check for NaN within a Blueprint?
The only semi-relevant function I see is “String: Is Numeric,” which “Checks if a string contains only numeric characters.” Converting floats/vectors to Strings and checking all their characters doesn’t seem like the ideal way to do this operation.
Is there any other Blueprint solution, other than writing a Blueprint Function Library in C++ which calls something like FGenericPlatformMath::IsNaN?
In case anyone stumbles on this old question, my solution to this issue looks like this:
- I looked up what was the limit of 32-bit floats.
- I tried to enter it in the editor, but it doesn’t seem to accept scientific notation, so I just wrote the “long number” (+/-340000000000000000000000000000000000000)
- For some reason, the editor accepted that, but turned it into (+/-2337158474762289152.0)
- What I can actually coded:
VALUE>-2337158474762289152.0
AND
VALUE<2337158474762289152.0
This seems to work. The logic is, that NaN comparison always fails, so NaN gives the same result (false), as a valid number outside of that range.
This isn’t a great solution, but it’s efficient, and better that “converting to string, and checking String.isnumeric” (which didn’t even worked for me, in 4.20).
1 Like