I'm confused by this...
This is my function declaration and definition:
UFUNCTION(BlueprintPure, Category = "Spawn", meta = (BlueprintProtected))
void RandomEmptySpawnLocation(FVector& Location);
void AWormGameMode::RandomEmptySpawnLocation(FVector& Location)
{
TArray<int> RowWithSpaceID;
TArray<int> ColumnWithSpaceID;
for (auto rowID = 0; rowID < GridSlotsOccupiedMap.Num(); rowID++)
{
for (auto columnID = 0; columnID < GridSlotsOccupiedMap[0].BoolRow.Num(); columnID++)
{
if (!GridSlotsOccupiedMap[rowID][columnID])
{
RowWithSpaceID.Add(rowID);
ColumnWithSpaceID.Add(columnID);
}
}
}
int IDToUse = FMath::RandRange(0, RowWithSpaceID.Num() - 1);
UE_LOG(LogTemp, Warning, TEXT("IDToUse = %i"), IDToUse)
int MiddleColumnID = (GridWidth / GridBlockSize - 1) / 2;
int MiddleRowID = (GridHeight / GridBlockSize - 1) / 2;
Location.X = (ColumnWithSpaceID[IDToUse] - MiddleColumnID) * GridBlockSize;
Location.Y = 50.f;
Location.Z = (-RowWithSpaceID[IDToUse] + MiddleRowID) * GridBlockSize;
}
It simply check the bool map that contains the "Occupied/Empty" status for every grid slots, it stores the empty ones and then it picks one at random to be used as a spawn for pickup or player.
I am spawning 2 things, a pickup and a player, but as you can see from the console output, that function fired 4 times...
A row as ID ranging from 0 to 24 so ID 22 is the purple player, and ID 42 is the red pickup (24 + 18). But, there is nothing at ID 291 and 441...furthermore, I debugged step by step and only 2 spawn events happen, not 4... so why is my function called twice from every spawn event inside blueprint?!
I'll put below also the linkage of the function in blueprint, in case help to answer my doubt.