Is this a If statement bug?

If i write this code it will not work.

if (SomeMatinee->MatineeControllerName == "FLWeather")

If i write this code it will not work

void AWeatherSystem::BeginPlay()
   FName WeatherName = "FLWeather";

  if (SomeMatinee->MatineeControllerName == WeatherName)

If i write this code it will work

void AWeatherSystem::BeginPlay()
    FName WeatherName = "FLWeather";

      bool bIsSameId = WeatherName.Compare(SomeMatinee->MatineeControllerName);
      UE_LOG(LogWeather, Log, TEXT("AWeatherSystem::BeginPlay() bIsSameId = %s"), bIsSameId ? TEXT("TRUE") : TEXT("FALSE"));

      if (bIsSameId)
         //works fine

If i write this code it will work

if (WeatherName.Compare(SomeMatinee->MatineeControllerName))
//or this will work
if (SomeMatinee->MatineeControllerName.Compare("FLWeather"))

Why will it not work with the 1st 2 ifs? is it a bug?

The == operator can be used to compare two FNames, and returns true or false. Rather than doing string comparisons, this compares the values in Index, which is a significant CPU savings.”

So, u need to ise it like this:

FName WeatherName = FName(TEXT("FLWeather"));

if (SomeMatinee->MatineeControllerName == WeatherName)

Followed Epics page and that will not work. Also tried this and it will not work

if (SomeMatinee->MatineeControllerName == FName(TEXT("FLWeather"))

So i’m going to use this as it will work

if (SomeMatinee->MatineeControllerName.Compare("FLWeather"))

Somethings must be wrong with FName in the if statements. They will not check right until i use compare then the if checks fine. Thanks for the info and the reply.

Your code works as expected. You are getting the same result with FName.Compare and the == operator. The Compare function returns an int not a bool and it returns 0 if the two FNames are equal which implicitly converts to false.

What if someone adds this into the UnrealString.h file, Edited to work with compare

FORCEINLINE friend bool operator==(const class FName& Lhs, const class FName& Rhs)
   bool bResult = false;
   int32 Result = 0;

        Result = Lhs.Compare(Rhs);
        bResult = Result = 0 ? true : false;

   return bResult

If i am not mistaken that will then let us check an fname against a fname in the if properly?

As already stated… Compare returns and int, which is 0 when both are equals, which then translates to false if used directly, which then gives you the opposite result than the expected one. In practice:

if (SomeMatinee->MatineeControllerName.Compare("FLWeather"))
    // NOT equal

if (SomeMatinee->MatineeControllerName.Compare("FLWeather") == 0)
    // equal

So your telling me that this

if (SomeMatinee->MatineeControllerName.Compare("FLWeather")) { // NOT equal }// this code works, it is not a zero 0=false.  if it is false or 0. I could not get into it.

Then how do i get into it then? if a if is false. it does not let you in and i get into that with that code. So it is not returning a 0 it has to be a 1 or i would not be getting into it.

If the if was working right, whether it is a true or a 1. Then why does this not return right value. None of these work and if the if worked right i would be able to get into all 3 of those but it will not let you into them. All 3 of those should give a true or a 1. Not a false or a 0

//SomeMatinee->MatineeControllerName is "FLWeather"
if (SomeMatinee->MatineeControllerName == "FLWeather")//if the if worked right like it should i would be getting into this, but i do not get thru as its a 0 or a false. they match

void AWeatherSystem::BeginPlay() { FName WeatherName = "FLWeather"; if (SomeMatinee->MatineeControllerName == WeatherName) }

if (SomeMatinee->MatineeControllerName == FName(TEXT("FLWeather")

I will log all this and figure it out. Makes no ■■■■ sense, lets return a 0 for compare, if it compares, wtf? When did 0 become a true or a 1? Whos genius idea was that; shakes head.

For me operator “==” with fnames working as intended. Also if you use compare() docs says: “FName::Compare can also be used to compare two FNames, and it will return less than 0 if this less than Other, 0 if this equal to Other, and greater than 0 if this greater than Other.”

You are overcomplicating things. Your FNames are clearly not equal if you enter the if branch (or don’t enter it when using ==). There is no question here whether Compare or == “work” (they do), if you expect your FNames to be equal but they aren’t, you simply have a bug somewhere in your code.

I will gather all the code that makes this and show you it all and you point out the bug to me. and lets completely forget about compare and concentrate on the if bug. I will have the code up in half hour or so. Have a few things to do here this morning before i can up the code.

Here is the code

void AWeatherSystem::BeginPlay()
   bool bWeatherFound = false;
   FName WeatherName = FName(TEXT("FLWeather"));


       TheLevel = GetLevel();
        UE_LOG(LogWeather, Log, TEXT("AWeatherSystem::BeginPlay() *TheLevel is %s"), *TheLevel->GetName());

       if (TheLevel != nullptr)
             for (int32 i = 0; i < TheLevel->Actors.Num(); i++)
                 if (TheLevel->Actors*->IsA<AMatineeActor>())
                       class AMatineeActor* const SomeMatinee = Cast<AMatineeActor>(TheLevel->Actors*);
                       UE_LOG(LogWeather, Log, TEXT("AWeatherSystem::BeginPlay() SomeMatinee is %s"), *SomeMatinee->GetName());

                     //SomeMatinee->MatineeControllerName is set as "FLWeather"
                     if (SomeMatinee->MatineeControllerName == WeatherName)//will not let me in and it should as they match!
                          //defined in h file as AMatineeActor* CurrentMatinee; with FName as "FLWeather" set in properties in editor.
                          CurrentMatinee = Cast<AMatineeActor>(TheLevel->Actors*);
                          bWeatherFound = true;
                           UE_LOG(LogWeather, Log, TEXT("AWeatherSystem::BeginPlay() CurrentMatinee is %s"), *CurrentMatinee->GetName());

                          if (GetWorldTimerManager().IsTimerActive(TimerHandle_Weather))

         if(bWeatherFound && (!GetWorldTimerManager().IsTimerActive(TimerHandle_Weather)))
             bWeatherFound = false;
             GetWorldTimerManager().SetTimer(TimerHandle_Weather, this, &AWeatherSystem::StartTheTimeLine, 1.0, true);
             GEngine->AddOnScreenDebugMessage(-1, 1.1f, FColor::Green, FString::Printf(TEXT("Weather Matinee has Started up!")));
             UE_LOG(LogWeather, Log, TEXT("Weather Matinee has Started up, LOAD THE REST UP! :)"));

please point out the bug, thanks

You are logging SomeMatinee->GetName() but trying to compare SomeMatinee->MatineeControllerName
Log SomeMatinee->MatineeControllerName and WeatherName and you will see that they don’t match

ok how do you print the SomeMatinee->MatineeControllerName? as it is set as “FLWeather” and so is the WeatherName = “FLWeather” and your telling me they will not match?

“FLWeather” == “FLWeather” looks like a match to me.

So your telling me that *SomeMatinee->GetName() is wrong? i have multiple Matinees so i have to check thru them until i find the one named “FLWeather”. which is in one of the SomeMatinee->MatineeControllerName which is “FLWeather”.

If that is so wrong then what would the if look like to run right? i want to see an if run this with no compare used to show me that this is not an if bug. I see an if bug here. I am sorry but this does not check FNames against FNames correctly.

If it did then this would work

if (SomeMatinee->MatineeControllerName == WeatherName)

You are assuming that SomeMatinee->MatineeControllerName is set as “FLWeather” and that WeatherName is set as"FLWeather" but I don’t see you logging their values anywhere to really check that.

Just putting the following lines right BEFORE the “if” will tell you that:

UE_LOG(LogWeather, Log, TEXT("MatineeControllerName is %s"), *SomeMatinee->MatineeControllerName);
UE_LOG(LogWeather, Log, TEXT("WeatherName is %s"), *WeatherName);

It must be

UE_LOG(LogWeather, Log, TEXT("MatineeControllerName is %s"), *SomeMatinee->MatineeControllerName.ToString());
UE_LOG(LogWeather, Log, TEXT("WeatherName is %s"), *WeatherName.ToString());

but otherwise yes, you will in all likelyhood see that they are not equal.

I put in your logs and am compiling now. will have results in a bit and i will post them here and update this post.

you were right, the **** MatineeControllerName is not FLWeather

[2021.03.05-21.46.24:448] 81]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee is FLWeather
[2021.03.05-21.46.24:448] 81]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee->MatineeControllerName is K2Node_MatineeController_0
[2021.03.05-21.46.24:448] 81]LogWeather: AWeatherSystem::BeginPlay() WeatherName is FLWeather

Not sure where K2Node_MatineeController_0 has come from, trying to solve that.

Also in the editor the properties window on right at top there is a place to set a name for the matinee. For some reason i thought that was the MatineeControllerName but it is not. That blank space we put in a name into the actor itself not the MatineeControllerName. That is where i messed up at.

While we are on this subject. Where the heck do you put in the MatineeControllerName at? I have not found a place in the editor to actually put that name in.

for the time being i am using this as the if

    if (*SomeMatinee->GetName() == WeatherName)

Here are my logs for all 3 matinee i have in my map

021.03.05-22.28.49:255][332]LogWeather: AWeatherSystem::BeginPlay() TheLevel->Actor is FLWeather
[2021.03.05-22.28.49:255][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee is FLWeather
[2021.03.05-22.28.49:255][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee->MatineeControllerName is K2Node_MatineeController_0
[2021.03.05-22.28.49:255][332]LogWeather: AWeatherSystem::BeginPlay() WeatherName is FLWeather
[2021.03.05-22.28.49:255][332]LogWeather: AWeatherSystem::BeginPlay() CurrentMatinee is FLWeather

[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() TheLevel->Actor is MatineeActor_1
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee is MatineeActor_1
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee->MatineeControllerName is None
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() WeatherName is FLWeather

[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() TheLevel->Actor is MatineeActor2_4
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee is MatineeActor2_4
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() SomeMatinee->MatineeControllerName is None
[2021.03.05-22.28.49:256][332]LogWeather: AWeatherSystem::BeginPlay() WeatherName is FLWeather

How did i get

 SomeMatinee->MatineeControllerName is K2Node_MatineeController_0

as my matinee name when the others did not get one?

Thanks for your time and efforts to get me on the right track, appreciated.

“MatineeControllerName - Name of controller node in level script, used to know what function to try and find for events”(c)docs.unrealengine. I don’t think you can change it yourself.

I want to thank you guys again for your time and efforts at helping solve my stupid bug.
thanks **HorusWM, Grim ヤ, and _brunocoimbra for everything.

Now that i got that fixed i was able to enable some of the systems in the weather system. It is nice to see fog getting thicker or lighter(depending on atmospheric conditions) as you play. :slight_smile: Thanks a ton guys, hopefully soon i will have a fully operational weather system controlling everything automatically.**