What is the C++ Equivilent of FindPlayerStart in Unreal Engine Blueprints?
The function on GameModeBase is not virtual; even though it can be overridden in blueprints.
Lots of older examples from around 4.3 seem to suggest there is a FindPlayerStart_Implementation function but I can’t find it in 4.19.
How can I achieve the same behavior as overriding FindPlayerStart and returning my own PlayerStart Actor in a blueprint?
It’s a kismet function:
UFUNCTION(BlueprintPure, Category=Game, meta = (DisplayName = "FindPlayerStart"))
AActor* K2_FindPlayerStart(AController* Player, const FString& IncomingName = TEXT(""));
Why do you need override a function just for casting?
You can create your own to call the original one, already casted to the type of Actor you need.
I’m trying to override it to implement logic in C++ to find my own PlayerStart based upon multiplayer teams.
I’m aware that it’s possible to do this via the FindPlayerStart method in Blueprints but I can’t do it the same way via C++ because the method is not virtual.
You can override AGameModeBase::InitNewPlayer and pass in the FName of your PlayerStart as the Portal parameter. InitNewPlayer calls FindPlayerStart, which searches through the PlayerStart objects for one that matches your name.
Thanks jCoder, what if you want to change the PlayerStart every time the player loads?
Do you mean a completely random position on the map, or do you mean random from a list of PlayerStarts?
Based upon a pre-selected list of chosen Player Starts.
Put the names of the Player Start actors into a String Table. At startup, load the String Table into a TArray<FString>, then do a random shuffle on the array. Now you can just use an index into the array to get the next random name to pass to InitNewPlayer.
Fantastic, thankyou!
APlayerStart* MyGameState::FindPlayerStartByName(const FString& IncomingName) const
{
if (IncomingName.IsEmpty())
{
return nullptr;
}
const UWorld* World = GetWorld();
const FName IncomingPlayerStartTag = FName(*IncomingName);
for (TActorIterator<APlayerStart> Iter(World); Iter; ++Iter)
{
APlayerStart* Start = *Iter;
if (Start && (Start->PlayerStartTag == IncomingPlayerStartTag))
{
return Start;
}
}
return nullptr;
}