I just remembered something I left out.
I recommend logging errors/warnings/etc to the log so that you can find out what went wrong.
You can add a “else” statment to the checks like this:
else
{
FString msg( TEXT( "Failed to do X" ) );
UE_LOG( LogTemp, Error, TEXT( "%s" ), *msg );
}
I have created these global functions to handle this for me:
void LogInfo( const FString& Function, const int LineNumber, const FString& Message, const bool SendToLog,
const bool AddToScreen, const float Duration )
{
if ( SendToLog || AddToScreen )
{
FString msg( TEXT( "" ) );// ( TEXT( "[ServerSetEnergyCell_Implementation] Cell parameter is null!" ) );
msg.Append( Function );
msg.Append( TEXT( "] Line " ) );
msg.AppendInt( LineNumber );
msg.Append( TEXT( ", Msg: " ) );
msg.Append( Message );
if ( SendToLog )
UE_LOG( LogTemp, Log, TEXT( "%s" ), *msg );
if ( AddToScreen && GEngine )
GEngine->AddOnScreenDebugMessage( INDEX_NONE, Duration, FColor::Green, msg );
}
}
void LogError( const FString& Function, const int LineNumber, const FString& Message, const bool SendToLog,
const bool AddToScreen, const float Duration )
{
if ( SendToLog || AddToScreen )
{
FString msg( TEXT( "" ) );// ( TEXT( "[ServerSetEnergyCell_Implementation] Cell parameter is null!" ) );
msg.Append( Function );
msg.Append( TEXT( "] Line " ) );
msg.AppendInt( LineNumber );
msg.Append( TEXT( ", Msg: " ) );
msg.Append( Message );
if ( SendToLog )
UE_LOG( LogTemp, Error, TEXT( "%s" ), *msg );
if ( AddToScreen && GEngine )
GEngine->AddOnScreenDebugMessage( INDEX_NONE, Duration, FColor::Red, msg );
}
}
void LogWarning( const FString& Function, const int LineNumber, const FString& Message, const bool SendToLog,
const bool AddToScreen, const float Duration )
{
if ( SendToLog || AddToScreen )
{
FString msg( TEXT( "" ) );// ( TEXT( "[ServerSetEnergyCell_Implementation] Cell parameter is null!" ) );
msg.Append( Function );
msg.Append( TEXT( "] Line " ) );
msg.AppendInt( LineNumber );
msg.Append( TEXT( ", Msg: " ) );
msg.Append( Message );
if ( SendToLog )
UE_LOG( LogTemp, Warning, TEXT( "%s" ), *msg );
if ( AddToScreen && GEngine )
GEngine->AddOnScreenDebugMessage( INDEX_NONE, Duration, FColor::Yellow, msg );
}
}