Hello all,
I’m trying to get the player id for a controller inside a function in its code. For whatever reason, this causes an access violation.
I can get the player IDs from the GameState player array just fine, but say this code in my PlayerController’s set pawn function creates an access violation.
int32 PID = PlayerState->PlayerId;
I know that each controller has a playerstate, so not sure why this is causing a violation. Since this core seemed to work fine:
InitialID = GetWorld()->GetGameState()->PlayerArray[0]->PlayerId;
I thought I would try and find the player controllers playerid using a similar method above.
int32 PlayerIndex = GetWorld()->GetGameState()->PlayerArray.Find(PlayerState);
PlayerID = GetWorld()->GetGameState()->PlayerArray[PlayerIndex]->PlayerId;
but this fails as well, as the find on the array returns a negative index. So im not sure what to do from here. This code is used to determine what pawn a player gets, based on the player number they are.