How do i use Fmath::Max?

Are you including the library? Pretty sure it is:
#include “Kismet/KismetMathLibrary.h”

Then FMath::Max3(health, mana, energy);

Well I just tested it, and it works. Here is exactly what I did:

In the header file, added this (not actually necessary, as pointed out by below):

#include "Kismet/KismetMathLibrary.h"

In the .cpp file, added this:

float a = 1.1; float b = 2.2; float c = 3.3;
float d = FMath::Max3(a, b, c);
UE_LOG(LogTemp, Warning, TEXT("The max is: %f"), d);

I added this to a collision box just for testing, and when I run into it, it logs “The max is: 3.3”

I am trying to figure out how to actually USE Max.

I want to find the max value between 3 values in one of my functions, but i can’t figure out how i am supposed to use this.

template<class T>
static T Max3(const T A, const T B, const T C);

void AWTCPlayerState::findMax(){

	Max3(health, mana, energy);
}

I get this error if i try to use it.

error C2129: static function 'T Max3<int>(const T,const T,const T)' declared but not defined
1>          with
1>          [
1>              T=int
1>          ]

I tried that and it gave me errors, and i have included the core/fmath library.

EDIT: It gives me an error, and i edited my post.

That worked, Thanks!

FMath is not part of KismetMathLibrary but UnrealMathUtility, it should work without any include as it being included via project main header file (ProjectName.h). I used FMath frequintly and never need to include anything

1 Like

Good catch, updated my comment above.

you should use like:

 Max3<float>(health, mana, energy);