Have you tried “GetTransform()” instead of “GetTransform” ?
Hello everyone,
I am trying to get my AI to spawn at a different position each time one is spawned but I am getting a error when spawning the character. My error is error C3867: ‘AActor::GetTransform’: non-standard syntax; use ‘&’ to create a pointer to member and this is my code
Code:
void AAuroraSurvivalGamemode::OnSpawnWave(TSubclassOf<AAuroraBaseAICharacter> enemyClassToSpawn, int32 enemiesToSpawn)
{
// Creating Spawn Params
FActorSpawnParameters spawnParams;
spawnParams.Instigator = Instigator;
spawnParams.Owner = this;
// For loop for spawning enemies
for (int32 i = 1; i <= enemiesToSpawn; i++)
{
// Generate random number for spawn switching
int32 randomNum = FMath::RandRange(0, spawnLocations.Num());
// Recast the array to the correct object
TArray<AAuroraAISpawnPoint*>& CastedArray = reinterpret_cast<TArray<AAuroraAISpawnPoint*>&>(spawnLocations);
AAuroraBaseAICharacter* AiCharacter = GetWorld()->SpawnActor<AAuroraBaseAICharacter>(enemyClassToSpawn, CastedArray[randomNum]->GetTransform, spawnParams);
// Increment enemies alive
currentEnemiesAlive++;
}
// Increase the current wave count
currentWave++;
// Debug message on new round
GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, TEXT("Current Wave: ") + FString::SanitizeFloat(currentWave));
}
My error is on the spawn character line. I am completely out of ideas on how to fix this
Thanks
It complies now but when I run my game it crashes right away
It would help if you could share why it is crashing.
At a glance the only things I can see are:
- GetWorld() might be returning null
- randomNum might be larger than length of casted array (arrays are zero indexed)
It triggers a break right now I think it could be related to getting the spawn points using UGameplayStatistics::GetAllActorsOfClass