At least i assume that’s where the error is…
Basically i’m getting this error when i try to run the game from within the editor:
which breaks here (large image 2560*1440):
the error reads:
template< class T > T* CastChecked( UObject* Src, ECastCheckedType::Type CheckType = ECastCheckedType::NullChecked )
{
CATCH_UNSUPPORTED_INTERFACECAST(T);
#if !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
if( (!Src && CheckType == ECastCheckedType::NullChecked) || (Src && !Src->template IsA<T>() ) )
{
CastLogError(Src ? *Src->GetFullName() : TEXT("NULL"), *T::StaticClass()->GetName()); //<----- error on this line
}
#endif // !(UE_BUILD_SHIPPING || UE_BUILD_TEST)
return (T*)Src;
}
But when i try to step into the code this happens:
I don’t feel brave enough to try and do everything through the full source code yet. But this apparently means i can’t debug some errors properly, so i was wondering if anybody might be able to see the issue?
Here’s the team selection logic:
void ASmashyGameMode::PostLogin(APlayerController* NewPlayer)
{
//place player on a team before Super (VoIP team based init, findplayerstart, etc.)
ASmashyPlayerState* NewPlayerState = CastChecked<ASmashyPlayerState>(NewPlayer->PlayerState);
const int32 TeamNum = ChooseTeam(NewPlayerState);
NewPlayerState->SetTeamNum(TeamNum);
Super::PostLogin(NewPlayer);
//Update spectator location for client
ASmashyPlayerController* NewPC = Cast<ASmashyPlayerController>(NewPlayer);
if (NewPC && NewPC->GetPawn() == NULL)
{
NewPC->ClientSetSpectatorCamera(NewPC->GetSpawnLocation(), NewPC->GetControlRotation());
}
//Notify new player if match is already in progress
if (NewPC && IsMatchInProgress())
{
NewPC->ClientGameStarted();
NewPC->ClientStartOnlineGame();
}
}
int32 ASmashyGameMode::ChooseTeam(ASmashyPlayerState* ForPlayerState) const
{
//create an array of teams
TArray<int32> TeamBalance;
TeamBalance.AddZeroed(NumTeams);
//get current team balance
for (int32 i = 0; i < GameState->PlayerArray.Num(); i++)
{
ASmashyPlayerState const* const TestPlayerState = Cast<ASmashyPlayerState>(GameState->PlayerArray*);
if (TestPlayerState && TestPlayerState != ForPlayerState && TeamBalance.IsValidIndex(TestPlayerState->GetTeamNum()))
{
TeamBalance[TestPlayerState->GetTeamNum()]++;
}
}
//find least populated team
int32 BestTeamScore = TeamBalance[0];
for (int32 i = 1; i < TeamBalance.Num(); i++)
{
if (BestTeamScore > TeamBalance*)
{
BestTeamScore = TeamBalance*;
}
}
//there could be more than one (useful if > 2 teams in match/game)
//also if both teams are even
TArray<int32> BestTeams;
for (int32 i = 0; i < TeamBalance.Num(); i++)
{
if (TeamBalance* == BestTeamScore)
{
BestTeams.Add(i);
}
}
//get random number from best list
const int32 RandomBestTeam = BestTeams[FMath::RandHelper(BestTeams.Num())];
return RandomBestTeam;
}