You need to make sure that you included the header file that contains the function
Then do something like this!
bool IsCloserThanDistance = FMath::IsNearlyEqual(CloserThanDistance , HorizontalDistance, CloseDistanceBuffer);
I’ve just begun getting into learning the Engine’s API and am quite rusty when it comes to C++.
In a test that I was doing, I was trying to compare values and coming from Blueprints, I wanted to call upon the Nearly Equal Function. I googled it up and it was this:
However, I’m not entirely sure of how to call it since I know that putting it into a Cpp file within a function as it’s shown will result in a block-illegal calling action.
An example of how I was looking to use it with code that already works:
CloserThanDistance = bool (((IsCloserThanDistance+ CloseDistanceBuffer) > HorizontalDistance) && ((IsCloserThanDistance - CloseDistanceBuffer) < HorizontalDistance));
How could I insert IsNearlyEqual(HorizontalDistance, IsCloserThanDistance, CloseDistanceBuffer) in a proper way so that it successfully returns the boolean value without an illegal action result at compile time?
Thanks! That worked like a charm. Quick question. I’m getting an error which I do not yet understand why it is an error.
The Code is as follows:
TriDistance = ((Vector2.X - Vector1.X) ^ 2) + ((Vector2.Y - Vector1.Y) ^ 2) + ((Vector2.Z - Vector1.Z) ^ 2);
Where TriDistance is defined in the .h as a float. When compiled, however, it says that the “^” is illegal since left operand has type “float.”
How should I write it?
You should not include header file in absolute path, UE tools don’t expect you to do so there might lead to potential unexpected breaks in future. You would also not pass plugin validation test for marketplace with that.
UBT automatically add include paths to the Public folder of each module so cut the path to the Public, so it should look like this:
I did include it as you wrote it.
I’m still getting that error. “Illegal, left operand has type float” C2296.
It seems like I forgot that ^ is not a Power symbol in C.
I used FMath::Pow(x, y).
thank you for your time.
Thanks for pointing that out Shadowriver. I learn something new about the UBT every day.