Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do i use Fmath::Max?

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>          ]

Product Version: UE 4.7
more ▼

asked Jun 09 '15 at 11:38 PM in C++ Programming

avatar image

91 30 30 32

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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

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

more ▼

answered Jun 10 '15 at 12:07 AM

avatar image

135 17 13 23

avatar image DrakeWalker Jun 10 '15 at 12:16 AM

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.

avatar image pagancyc Jun 10 '15 at 12:30 AM

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 Shadowriver 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"

avatar image DrakeWalker Jun 10 '15 at 12:59 AM

That worked, Thanks!

avatar image Shadowriver Jun 10 '15 at 03:02 AM

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

avatar image pagancyc Jun 10 '15 at 03:12 AM

Good catch, updated my comment above.

(comments are locked)
10|2000 characters needed characters left

you should use like:

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

more ▼

answered Jan 15 '18 at 12:52 PM

avatar image

8 3 3

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question