PlayerStart Choosing finally works!

pull/5/head
eyakm1 2 years ago
parent 29c31b81af
commit d110245ba7

@ -12,7 +12,7 @@ bOffsetPlayerGamepadIds=False
GameInstanceClass=/Script/Engine.GameInstance
GameDefaultMap=/Game/MainMenu/MainMenuLevel.MainMenuLevel
ServerDefaultMap=/Engine/Maps/Entry.Entry
GlobalDefaultGameMode=/Script/TurnBasedTutorial.MyGameMode
GlobalDefaultGameMode=/Script/Engine.GameMode
GlobalDefaultServerGameMode=None
[/Script/HardwareTargeting.HardwareTargetingSettings]

Binary file not shown.

@ -15,27 +15,30 @@ AMyGameMode::AMyGameMode() : Super()
AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player)
{
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers());
InitializeSpawnPointsIfNeeded();
InitializeSpawnPointsIfNeeded(Player);
auto ptr = *SpawnPoints.Find(GetNumPlayers());
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex());
return ptr;
}
void AMyGameMode::InitializeSpawnPointsIfNeeded()
void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player)
{
if (SpawnPoints.Num() != 0)
{
return;
}
for (TActorIterator <AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) {
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex());
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator);
auto World = GetWorld();
for (TActorIterator<AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator)
{
auto PlayerStart = *PlayerStartIterator;
UClass* PawnClass = GetDefaultPawnClassForController(Player);
APawn* PawnToFit = PawnClass ? PawnClass->GetDefaultObject<APawn>() : nullptr;
FVector ActorLocation = PlayerStart->GetActorLocation();
const FRotator ActorRotation = PlayerStart->GetActorRotation();
if (!World->EncroachingBlockingGeometry(PawnToFit, ActorLocation, ActorRotation))
{
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *PlayerStartIterator);
UE_LOG(LogTemp, Warning, TEXT("PlayerStart unoccupied iterator %d"), PlayerStartIterator->GetPlayerIndex());
}
}
// TArray<AActor*> MyPlayerStartObjects;
// UGameplayStatics::GetAllActorsOfClass(GetWorld(), AMyPlayerStart::StaticClass(), MyPlayerStartObjects);
// for (const auto& PlayerStart : MyPlayerStartObjects)
// {
// SpawnPoints.Add(dynamic_cast<AMyPlayerStart*>(PlayerStart)->GetPlayerIndex(),
// dynamic_cast<AMyPlayerStart*>(PlayerStart));
// }
}

@ -20,10 +20,10 @@ class TURNBASEDTUTORIAL_API AMyGameMode : public AGameMode
public:
AMyGameMode();
AActor* ChoosePlayerStart_Implementation(AController* Player);
virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;
private:
void InitializeSpawnPointsIfNeeded();
void InitializeSpawnPointsIfNeeded(AController *Player);
TMap<uint8, AMyPlayerStart*> SpawnPoints;
};

@ -4,32 +4,32 @@
#include "MyPawn.h"
// Sets default values
AMyPawn::AMyPawn()
{
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyPawn::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
// Called to bind functionality to input
void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
}
// // Sets default values
// AMyPawn::AMyPawn()
// {
// // Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
// PrimaryActorTick.bCanEverTick = true;
//
// }
//
// // Called when the game starts or when spawned
// void AMyPawn::BeginPlay()
// {
// Super::BeginPlay();
//
// }
//
// // Called every frame
// void AMyPawn::Tick(float DeltaTime)
// {
// Super::Tick(DeltaTime);
//
// }
//
// // Called to bind functionality to input
// void AMyPawn::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
// {
// Super::SetupPlayerInputComponent(PlayerInputComponent);
//
// }
//

@ -11,21 +11,21 @@ class TURNBASEDTUTORIAL_API AMyPawn : public APawn
{
GENERATED_BODY()
public:
// Sets default values for this pawn's properties
AMyPawn();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
// Called to bind functionality to input
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
// public:
// // Sets default values for this pawn's properties
// AMyPawn();
//
// protected:
// // Called when the game starts or when spawned
// virtual void BeginPlay() override;
//
// public:
// // Called every frame
// virtual void Tick(float DeltaTime) override;
//
// // Called to bind functionality to input
// virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
//
//
};

Loading…
Cancel
Save