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 GameInstanceClass=/Script/Engine.GameInstance
GameDefaultMap=/Game/MainMenu/MainMenuLevel.MainMenuLevel GameDefaultMap=/Game/MainMenu/MainMenuLevel.MainMenuLevel
ServerDefaultMap=/Engine/Maps/Entry.Entry ServerDefaultMap=/Engine/Maps/Entry.Entry
GlobalDefaultGameMode=/Script/TurnBasedTutorial.MyGameMode GlobalDefaultGameMode=/Script/Engine.GameMode
GlobalDefaultServerGameMode=None GlobalDefaultServerGameMode=None
[/Script/HardwareTargeting.HardwareTargetingSettings] [/Script/HardwareTargeting.HardwareTargetingSettings]

Binary file not shown.

@ -15,27 +15,30 @@ AMyGameMode::AMyGameMode() : Super()
AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player) AActor* AMyGameMode::ChoosePlayerStart_Implementation(AController* Player)
{ {
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers()); UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart %d"), GetNumPlayers());
InitializeSpawnPointsIfNeeded(); InitializeSpawnPointsIfNeeded(Player);
auto ptr = *SpawnPoints.Find(GetNumPlayers()); auto ptr = *SpawnPoints.Find(GetNumPlayers());
UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex()); UE_LOG(LogTemp, Warning, TEXT("GameMode ChoosePlayerStart end %d"), ptr->GetPlayerIndex());
return ptr; return ptr;
} }
void AMyGameMode::InitializeSpawnPointsIfNeeded() void AMyGameMode::InitializeSpawnPointsIfNeeded(AController* Player)
{ {
if (SpawnPoints.Num() != 0) if (SpawnPoints.Num() != 0)
{ {
return; return;
} }
for (TActorIterator <AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator) { auto World = GetWorld();
UE_LOG(LogTemp, Warning, TEXT("PlayerStart iterator %d"), PlayerStartIterator->GetPlayerIndex()); for (TActorIterator<AMyPlayerStart> PlayerStartIterator(GetWorld()); PlayerStartIterator; ++PlayerStartIterator)
SpawnPoints.Add(PlayerStartIterator->GetPlayerIndex(), *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: public:
AMyGameMode(); AMyGameMode();
AActor* ChoosePlayerStart_Implementation(AController* Player); virtual AActor* ChoosePlayerStart_Implementation(AController* Player) override;
private: private:
void InitializeSpawnPointsIfNeeded(); void InitializeSpawnPointsIfNeeded(AController *Player);
TMap<uint8, AMyPlayerStart*> SpawnPoints; TMap<uint8, AMyPlayerStart*> SpawnPoints;
}; };

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

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

Loading…
Cancel
Save