So while using logs (UE_LOG) throughout my code to debug my game development, I’ve been running into this issue constantly that just does not seem to really make much sense where UE_LOG will completely crash the game if the variable it is trying to log is not there (NULL). I understand that C++ is a little more unforgiving than that of uScript from UDK, however whenever I would use uScript I could log a variable, and if that variable was null it would print out a “NONE” instead, and the game would go on. This was extremely helpfully if perhaps I ran into race conditions due to a bad system, and especially during Replication to figure out if a client received the right information.
In example, if I was logging a weapon instance, I could easily log the variable and determine if it was there or not.
In uScript I could do
`log("Character Weapon = "@Weapon);
this would produce a log saying “Character Weapon = None” if it failed.
In UE4, I would have to go with
UE_LOG(LogName,All,TEXT("Character Weapon = %s"),*Weapon->GetName());
Which produces an instant/fatal crash of the entire game if there is no Weapon. I don’t feel like I’m doing this right if this is the case, because what’s the point of logging if it can’t log the lack of something?
My current solution is to convert it into a hunky if statement
if(Weapon->GetName() == NULL)
{
UELOG(LogName,All,TEXT("NO WEAPON!"));
}
else
{
UE_LOG(LogName,All,TEXT("Character Weapon = %s"),*Weapon->GetName());
}
This results in extremely painful setups and conditioning just to log a variable to see if, or if not it is there. Can anyone explain to me what i’m doing wrong here?