fixed crashing bug when calling RandomHex() too early

This commit is contained in:
Maximilian Fajnberg 2022-01-11 18:16:26 +01:00
parent 832507177f
commit 9021763ab7
4 changed files with 12 additions and 4 deletions

View File

@ -39,7 +39,7 @@ void AAdventureCameraPawn::BeginPlay()
// The Viewport properties are inaccurate right after BeginPlay, so we need to wait a short time before saving them here. // The Viewport properties are inaccurate right after BeginPlay, so we need to wait a short time before saving them here.
FTimerHandle UnusedHandle; FTimerHandle UnusedHandle;
GetWorldTimerManager().SetTimer( GetWorldTimerManager().SetTimer(
UnusedHandle, this, &AAdventureCameraPawn::GetTheDamnViewport, 1.5, false); UnusedHandle, this, &AAdventureCameraPawn::GetTheDamnViewport, 1, false);
} }
void AAdventureCameraPawn::GetTheDamnViewport() void AAdventureCameraPawn::GetTheDamnViewport()

View File

@ -47,6 +47,7 @@ public:
UPROPERTY(BlueprintReadWrite, Category = "Runtime") UPROPERTY(BlueprintReadWrite, Category = "Runtime")
class AHexTile* SelectedHex; class AHexTile* SelectedHex;
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;

View File

@ -79,10 +79,12 @@ void AAdventureMap::MakeGrid()
{ {
tile->Index = GridIndex(tile->Q, tile->R); tile->Index = GridIndex(tile->Q, tile->R);
} }
bHexGridReady = true;
} }
AHexTile* AAdventureMap::RandomHex() AHexTile* AAdventureMap::RandomHex()
{ {
int32 SpawnHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize)); int32 RandHex = GridIndex(FMath::RandRange(0, GridSize), FMath::RandRange(0, GridSize));
return Grid[SpawnHex]; return Grid[RandHex];
} }

View File

@ -26,11 +26,16 @@ public:
int32 GridSize = 100; // squared is the number of Tiles int32 GridSize = 100; // squared is the number of Tiles
UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config") UPROPERTY(EditAnywhere, BlueprintReadOnly, Category = "Config")
int32 TileSize = 100; int32 TileSize = 100;
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "MapData")
UPROPERTY(BlueprintReadOnly, Category = "Generation")
bool bHexGridReady;
UPROPERTY(VisibleInstanceOnly, BlueprintReadWrite, Category = "Runtime")
TArray<AHexTile*> Grid; TArray<AHexTile*> Grid;
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
int32 GridIndex(int32 q, int32 r); int32 GridIndex(int32 q, int32 r);
// Player spawn section // Player spawn section
UPROPERTY(VisibleAnywhere, BlueprintReadWrite) UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
APawn* CameraPawn; APawn* CameraPawn;